11
11
from compas .geometry import Polyline
12
12
from compas .geometry import Rotation
13
13
from compas .geometry import Translation
14
+ from compas .geometry import Vector
14
15
from compas .geometry import is_coplanar
15
-
16
- try :
17
- from compas_view2 import app
18
- from compas_view2 .collections import Collection
19
- from compas_view2 .shapes import Arrow
20
- except ImportError :
21
- pass
16
+ from compas_viewer import Viewer
17
+ from compas_viewer .config import Config
18
+
19
+
20
+ class Arrow :
21
+ def __init__ (self , position = [0 , 0 , 0 ], direction = [0 , 0 , 1 ], linewidth = 0.02 ):
22
+ super ().__init__ ()
23
+ self .position = Vector (* position )
24
+ self .direction = Vector (* direction )
25
+ self .linewidth = linewidth
26
+
27
+ def add_to_scene (self , viewer , facecolor : Color , opacity = 1 ):
28
+ viewer .scene .add (
29
+ Vector (* self .direction ),
30
+ anchor = Point (* self .position ),
31
+ facecolor = facecolor ,
32
+ linecolor = facecolor ,
33
+ linewidth = self .linewidth ,
34
+ show_lines = True ,
35
+ opacity = opacity ,
36
+ )
22
37
23
38
24
39
def draw_blocks (assembly , viewer , edge = True , tol = 0.0 ):
@@ -50,25 +65,25 @@ def draw_blocks(assembly, viewer, edge=True, tol=0.0):
50
65
else :
51
66
blockedges .append (Line (* block .edge_coordinates (edge )))
52
67
if len (blocks ) != 0 :
53
- viewer .add (
54
- Collection ( blocks ) ,
68
+ viewer .scene . add (
69
+ blocks ,
55
70
show_faces = True ,
56
71
show_lines = False ,
57
72
opacity = 0.6 ,
58
- facecolor = (0.9 , 0.9 , 0.9 ),
73
+ facecolor = Color (0.9 , 0.9 , 0.9 ),
59
74
)
60
75
if len (supports ) != 0 :
61
- viewer .add (
62
- Collection ( supports ) ,
76
+ viewer .scene . add (
77
+ supports ,
63
78
show_faces = True ,
64
79
show_lines = False ,
65
80
opacity = 0.5 ,
66
81
facecolor = Color .from_hex ("#f79d84" ),
67
82
)
68
83
if len (blockedges ) != 0 :
69
- viewer .add (Collection ( blockedges ) , linewidth = 1.5 )
84
+ viewer .scene . add (blockedges , linewidth = 1.5 )
70
85
if len (supportedges ) != 0 :
71
- viewer .add (Collection ( supportedges ) , linecolor = Color .from_hex ("#f79d84" ), linewidth = 4 )
86
+ viewer .scene . add (supportedges , linecolor = Color .from_hex ("#f79d84" ), linewidth = 4 )
72
87
73
88
74
89
def draw_interfaces (assembly , viewer ):
@@ -94,15 +109,15 @@ def draw_interfaces(assembly, viewer):
94
109
interfaces .append (Mesh .from_polygons ([polygon ]))
95
110
96
111
if len (interfaces ) != 0 :
97
- viewer .add (
98
- Collection ( interfaces ) ,
112
+ viewer .scene . add (
113
+ interfaces ,
99
114
show_lines = False ,
100
115
show_points = False ,
101
116
facecolor = (0.8 , 0.8 , 0.8 ),
102
117
)
103
118
if len (faces ) != 0 :
104
- viewer .add (
105
- Collection ( faces ) ,
119
+ viewer .scene . add (
120
+ faces ,
106
121
linecolor = Color .from_hex ("#fac05e" ),
107
122
linewidth = 10 ,
108
123
pointsize = 10 ,
@@ -163,17 +178,17 @@ def draw_forces(assembly, viewer, scale=1.0, resultant=True, nodal=False):
163
178
else :
164
179
res_nn .append (Line (p1 , p2 ))
165
180
if len (locs ) != 0 :
166
- viewer .add (Collection ( locs ) , size = 12 , color = Color .from_hex ("#386641" ))
181
+ viewer .scene . add (locs , size = 12 , color = Color .from_hex ("#386641" ))
167
182
if len (res_np ) != 0 :
168
- viewer .add (Collection ( res_np ) , linewidth = 8 , linecolor = (0 , 0.3 , 0 ))
183
+ viewer .scene . add (res_np , linewidth = 8 , linecolor = Color (0 , 0.3 , 0 ))
169
184
if len (res_nn ) != 0 :
170
- viewer .add (Collection ( res_nn ) , linewidth = 8 , linecolor = (0.8 , 0 , 0 ))
185
+ viewer .scene . add (res_nn , linewidth = 8 , linecolor = Color (0.8 , 0 , 0 ))
171
186
if len (fnn ) != 0 :
172
- viewer .add (Collection ( fnn ) , linewidth = 5 , linecolor = Color .from_hex ("#00468b" ))
187
+ viewer .scene . add (fnn , linewidth = 5 , linecolor = Color .from_hex ("#00468b" ))
173
188
if len (fnp ) != 0 :
174
- viewer .add (Collection ( fnp ) , linewidth = 5 , linecolor = (1 , 0 , 0 ))
189
+ viewer .scene . add (fnp , linewidth = 5 , linecolor = Color (1 , 0 , 0 ))
175
190
if len (ft ) != 0 :
176
- viewer .add (Collection ( ft ) , linewidth = 5 , linecolor = (1.0 , 0.5 , 0.0 ))
191
+ viewer .scene . add (ft , linewidth = 5 , linecolor = Color (1.0 , 0.5 , 0.0 ))
177
192
178
193
179
194
def draw_forcesline (assembly , viewer , scale = 1.0 , resultant = True , nodal = False ):
@@ -241,17 +256,17 @@ def draw_forcesline(assembly, viewer, scale=1.0, resultant=True, nodal=False):
241
256
else :
242
257
res_nn .append (Line (p1 , p2 ))
243
258
if len (locs ) != 0 :
244
- viewer .add (Collection ( locs ) , pointsize = 12 , pointcolor = Color .from_hex ("#386641" ))
259
+ viewer .scene . add (locs , pointsize = 12 , pointcolor = Color .from_hex ("#386641" ))
245
260
if len (res_np ) != 0 :
246
- viewer .add (Collection ( res_np ) , linewidth = 8 , linecolor = (0 , 0.3 , 0 ))
261
+ viewer .scene . add (res_np , linewidth = 8 , linecolor = Color (0 , 0.3 , 0 ))
247
262
if len (res_nn ) != 0 :
248
- viewer .add (Collection ( res_nn ) , linewidth = 8 , linecolor = (0.8 , 0 , 0 ))
263
+ viewer .scene . add (res_nn , linewidth = 8 , linecolor = Color (0.8 , 0 , 0 ))
249
264
if len (fnn ) != 0 :
250
- viewer .add (Collection ( fnn ) , linewidth = 5 , linecolor = Color .from_hex ("#00468b" ))
265
+ viewer .scene . add (fnn , linewidth = 5 , linecolor = Color .from_hex ("#00468b" ))
251
266
if len (fnp ) != 0 :
252
- viewer .add (Collection ( fnp ) , linewidth = 5 , linecolor = (1 , 0 , 0 ))
267
+ viewer .scene . add (fnp , linewidth = 5 , linecolor = Color (1 , 0 , 0 ))
253
268
if len (ft ) != 0 :
254
- viewer .add (Collection ( ft ) , linewidth = 5 , linecolor = (1.0 , 0.5 , 0.0 ))
269
+ viewer .scene . add (ft , linewidth = 5 , linecolor = Color (1.0 , 0.5 , 0.0 ))
255
270
# print("total reaction: ", total_reaction)
256
271
257
272
@@ -286,21 +301,9 @@ def draw_forcesdirect(assembly, viewer, scale=1.0, resultant=True, nodal=False):
286
301
if (w * force * scale ).length == 0 :
287
302
continue
288
303
if flip :
289
- f = Arrow (
290
- pt ,
291
- w * force * scale * - 1 ,
292
- head_portion = 0.2 ,
293
- head_width = 0.07 ,
294
- body_width = 0.02 ,
295
- )
304
+ f = Arrow (pt , w * force * scale * - 1 , linewidth = 10 )
296
305
else :
297
- f = Arrow (
298
- pt ,
299
- w * force * scale ,
300
- head_portion = 0.2 ,
301
- head_width = 0.07 ,
302
- body_width = 0.02 ,
303
- )
306
+ f = Arrow (pt , w * force * scale , linewidth = 10 )
304
307
if force >= 0 :
305
308
fnp .append (f )
306
309
else :
@@ -312,17 +315,13 @@ def draw_forcesdirect(assembly, viewer, scale=1.0, resultant=True, nodal=False):
312
315
f = Arrow (
313
316
pt ,
314
317
ft_uv * - 1 ,
315
- head_portion = 0.2 ,
316
- head_width = 0.07 ,
317
- body_width = 0.02 ,
318
+ linewidth = 10 ,
318
319
)
319
320
else :
320
321
f = Arrow (
321
322
pt ,
322
323
ft_uv ,
323
- head_portion = 0.2 ,
324
- head_width = 0.07 ,
325
- body_width = 0.02 ,
324
+ linewidth = 10 ,
326
325
)
327
326
ft .append (f )
328
327
if resultant :
@@ -353,44 +352,32 @@ def draw_forcesdirect(assembly, viewer, scale=1.0, resultant=True, nodal=False):
353
352
if resultant_f .length >= thres :
354
353
locs .append (Point (* resultant_pos ))
355
354
if flip :
356
- f = Arrow (
357
- resultant_pos ,
358
- resultant_f * - 1 ,
359
- head_portion = 0.2 ,
360
- head_width = 0.07 ,
361
- body_width = 0.02 ,
362
- )
355
+ f = Arrow (resultant_pos , resultant_f * - 1 , linewidth = 10 )
363
356
else :
364
- f = Arrow (
365
- resultant_pos ,
366
- resultant_f ,
367
- head_portion = 0.2 ,
368
- head_width = 0.07 ,
369
- body_width = 0.02 ,
370
- )
357
+ f = Arrow (resultant_pos , resultant_f , linewidth = 10 )
371
358
if friction :
372
- viewer .add (f , facecolor = (1.0 , 0.5 , 0.0 ), show_lines = False )
359
+ viewer .scene . add (f , facecolor = (1.0 , 0.5 , 0.0 ), show_lines = False )
373
360
if not is_tension :
374
361
res_np .append (f )
375
362
else :
376
363
res_nn .append (f )
377
364
if len (locs ) != 0 :
378
- viewer .add (Collection ( locs ) , size = 12 , color = Color .from_hex ("#386641" ))
365
+ viewer .scene . add (locs , size = 12 , color = Color .from_hex ("#386641" ))
379
366
if len (res_np ) != 0 :
380
- viewer .add (Collection (res_np ), facecolor = Color .from_hex ("#386641" ), show_lines = False )
367
+ for arrow in res_np :
368
+ arrow .add_to_scene (viewer , facecolor = Color .from_hex ("#386641" ))
381
369
if len (res_nn ) != 0 :
382
- viewer .add (Collection (res_nn ), facecolor = (0.8 , 0 , 0 ), show_lines = False )
370
+ for arrow in res_nn :
371
+ arrow .add_to_scene (viewer , facecolor = Color (0.8 , 0 , 0 ))
383
372
if len (fnp ) != 0 :
384
- viewer .add (
385
- Collection (fnp ),
386
- facecolor = Color .from_hex ("#00468b" ),
387
- show_lines = False ,
388
- opacity = 0.5 ,
389
- )
373
+ for arrow in fnp :
374
+ arrow .add_to_scene (viewer , facecolor = Color .from_hex ("#00468b" ), opacity = 0.5 )
390
375
if len (fnn ) != 0 :
391
- viewer .add (Collection (fnn ), facecolor = (1 , 0 , 0 ), show_lines = False , opacity = 0.5 )
376
+ for arrow in fnn :
377
+ arrow .add_to_scene (viewer , facecolor = Color (1 , 0 , 0 ), opacity = 0.5 )
392
378
if len (ft ) != 0 :
393
- viewer .add (Collection (ft ), facecolor = (1.0 , 0.5 , 0.0 ), show_lines = False , opacity = 0.5 )
379
+ for arrow in ft :
380
+ arrow .add_to_scene (viewer , facecolor = Color (1.0 , 0.5 , 0.0 ), opacity = 0.5 )
394
381
395
382
396
383
def draw_displacements (assembly , viewer , dispscale = 1.0 , tol = 0.0 ):
@@ -425,9 +412,9 @@ def draw_displacements(assembly, viewer, dispscale=1.0, tol=0.0):
425
412
continue
426
413
blocks .append (Line (* new_block .edge_coordinates (edge )))
427
414
if len (blocks ) != 0 :
428
- viewer .add (Collection ( blocks ) , linewidth = 1 , linecolor = (0.7 , 0.7 , 0.7 ))
415
+ viewer .scene . add (blocks , linewidth = 1 , linecolor = Color (0.7 , 0.7 , 0.7 ))
429
416
if len (nodes ) != 0 :
430
- viewer .add (Collection ( nodes ) , pointcolor = (0.7 , 0.7 , 0.7 ))
417
+ viewer .scene . add (nodes , pointcolor = Color (0.7 , 0.7 , 0.7 ))
431
418
432
419
433
420
def draw_weights (assembly , viewer , scale = 1.0 , density = 1.0 ):
@@ -445,9 +432,7 @@ def draw_weights(assembly, viewer, scale=1.0, density=1.0):
445
432
Arrow (
446
433
block .center (),
447
434
[0 , 0 , - block .volume () * d * scale ],
448
- head_portion = 0.2 ,
449
- head_width = 0.07 ,
450
- body_width = 0.02 ,
435
+ linewidth = 0.02 ,
451
436
)
452
437
)
453
438
# print("self-weight", -block.volume() * density)
@@ -457,11 +442,12 @@ def draw_weights(assembly, viewer, scale=1.0, density=1.0):
457
442
# print("total self-weight: ", total_weights)
458
443
459
444
if len (supports ) != 0 :
460
- viewer .add (Collection ( supports ) , pointsize = 20 , pointcolor = Color .from_hex ("#ee6352" ))
445
+ viewer .scene . add (supports , pointsize = 20 , pointcolor = Color .from_hex ("#ee6352" ))
461
446
if len (blocks ) != 0 :
462
- viewer .add (Collection ( blocks ) , pointsize = 30 , pointcolor = Color .from_hex ("#3284a0" ))
447
+ viewer .scene . add (blocks , pointsize = 30 , pointcolor = Color .from_hex ("#3284a0" ))
463
448
if len (weights ) != 0 :
464
- viewer .add (Collection (weights ), facecolor = Color .from_hex ("#59cd90" ), show_lines = False )
449
+ for weight in weights :
450
+ weight .add_to_scene (viewer , facecolor = Color .from_hex ("#59cd90" ))
465
451
466
452
467
453
def cra_view (
@@ -524,7 +510,7 @@ def cra_view(
524
510
None
525
511
"""
526
512
527
- viewer = app . App ( width = 1600 , height = 1000 , viewmode = "shaded" , show_grid = grid )
513
+ viewer = Viewer ( config = Config ( vectorsize = 0.15 ) )
528
514
529
515
if blocks :
530
516
draw_blocks (assembly , viewer , edge , tol )
@@ -541,7 +527,7 @@ def cra_view(
541
527
if displacements :
542
528
draw_displacements (assembly , viewer , dispscale , tol )
543
529
544
- viewer .run ()
530
+ viewer .show ()
545
531
546
532
547
533
def cra_view_ex (
0 commit comments