-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtotjlib.py
870 lines (704 loc) · 32.8 KB
/
totjlib.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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# --------------------------------------------------------------------------
# Blendyn -- file totjlib.py
# Copyright (C) 2015 -- 2021 Andrea Zanoni -- andrea.zanoni@polimi.it
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This file is part of Blendyn, add-on script for Blender.
#
# Blendyn is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Blendyn is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Blendyn. If not, see <http://www.gnu.org/licenses/>.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
import bpy
import os
from mathutils import *
from math import *
from .utilslib import *
def parse_total(rw, ed):
""" Parses a total joint entry in .log file """
ret_val = True
try:
el = ed['total_joint_' + str(rw[1])]
eldbmsg({'PARSE_ELEM'}, "BLENDYN::parse_total():", el)
eldbmsg({'FOUND_DICT'}, "BLENDYN::parse_total():", el)
el.nodes[0].int_label = int(rw[2])
el.nodes[1].int_label = int(rw[24])
el.offsets[0].value = Vector(( float(rw[3]), float(rw[4]), float(rw[5]) ))
R1p = Matrix().to_3x3()
parse_rotmat(rw, 6, R1p)
el.rotoffsets[0].value = R1p.to_quaternion();
R1r = Matrix().to_3x3()
parse_rotmat(rw, 15, R1r)
el.rotoffsets[1].value = R1r.to_quaternion();
el.offsets[1].value = Vector(( float(rw[25]), float(rw[26]), float(rw[27]) ))
R2p = Matrix().to_3x3()
parse_rotmat(rw, 28, R2p)
el.rotoffsets[2].value = R2p.to_quaternion();
R2r = Matrix().to_3x3()
parse_rotmat(rw, 37, R2r)
el.rotoffsets[3].value = R2r.to_quaternion();
# note: this is not really an offset, but a bool vector
# indicating which position constraints are active
el.offsets[2].value = Vector(( float(rw[46]), float(rw[47]), float(rw[48]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which velocity constraints are active
el.offsets[3].value = Vector(( float(rw[49]), float(rw[50]), float(rw[51]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which rotation constraints are active
el.offsets[4].value = Vector(( float(rw[52]), float(rw[53]), float(rw[54]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which angular velocity constraints are active
el.offsets[5].value = Vector(( float(rw[55]), float(rw[56]), float(rw[57]) ))
if el.name in bpy.data.objects.keys():
el.blender_object = el.name
el.is_imported = True
# FIXME: this is here to enhance backwards compatibility.
# Should disappear in future versions
el.mbclass = 'elem.joint'
pass
except KeyError:
el = ed.add()
el.mbclass = 'elem.joint'
el.type = 'total_joint'
el.int_label = int(rw[1])
eldbmsg({'PARSE_ELEM'}, "BLENDYN::parse_total():", el)
eldbmsg({'NOTFOUND_DICT'}, "BLENDYN::parse_total():", el)
el.nodes.add()
el.nodes[0].int_label = int(rw[2])
el.nodes.add()
el.nodes[1].int_label = int(rw[24])
el.offsets.add()
el.offsets[0].value = Vector(( float(rw[3]), float(rw[4]), float(rw[5]) ))
el.rotoffsets.add()
R1p = Matrix().to_3x3()
parse_rotmat(rw, 6, R1p)
el.rotoffsets[0].value = R1p.to_quaternion();
el.rotoffsets.add()
R1r = Matrix().to_3x3()
parse_rotmat(rw, 15, R1r)
el.rotoffsets[1].value = R1r.to_quaternion();
el.offsets.add()
el.offsets[1].value = Vector(( float(rw[25]), float(rw[26]), float(rw[27]) ))
el.rotoffsets.add()
R2p = Matrix().to_3x3()
parse_rotmat(rw, 28, R2p)
el.rotoffsets[2].value = R2p.to_quaternion();
el.rotoffsets.add()
R2r = Matrix().to_3x3()
parse_rotmat(rw, 37, R2r)
el.rotoffsets[3].value = R2r.to_quaternion();
# NOTE: This is not really an offset, but a bool vector
# indicating which position constraints are active
el.offsets.add()
el.offsets[2].value = Vector(( float(rw[46]), float(rw[47]), float(rw[48]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which velocity constraints are active
el.offsets.add()
el.offsets[3].value = Vector(( float(rw[49]), float(rw[50]), float(rw[51]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which rotation constraints are active
el.offsets.add()
el.offsets[4].value = Vector(( float(rw[52]), float(rw[53]), float(rw[54]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which rotation constraints are active
el.offsets.add()
el.offsets[5].value = Vector(( float(rw[55]), float(rw[56]), float(rw[57]) ))
el.import_function = "blendyn.import_total"
el.info_draw = "total_info_draw"
el.name = el.type + "_" + str(el.int_label)
el.is_imported = True
ret_val = False
pass
return ret_val
# -----------------------------------------------------------
# end of parse_total(rw, ed) function
def parse_total_pin(rw, ed):
""" Parses a total pin joint entry in the .log file """
ret_val = True
try:
el = ed['total_pin_joint_' + str(rw[1])]
eldbmsg({'PARSE_ELEM'}, "BLENDYN::parse_total_pin():", el)
eldbmsg({'FOUND_DICT'}, "BLENDYN::parse_total_pin():", el)
el.nodes[0].int_label = int(rw[2])
el.offsets[0].value = Vector(( float(rw[3]), float(rw[4]), float(rw[5]) ))
R1p = Matrix().to_3x3()
parse_rotmat(rw, 6, R1p)
el.rotoffsets[0].value = R1p.to_quaternion();
R1r = Matrix().to_3x3()
parse_rotmat(rw, 15, R1r)
el.rotoffsets[1].value = R1r.to_quaternion();
# note: this is not really an offset, but a bool vector
# indicating which position constraints are active
el.offsets[1].value = Vector(( float(rw[45]), float(rw[46]), float(rw[47]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which velocity constraints are active
el.offsets[2].value = Vector(( float(rw[48]), float(rw[49]), float(rw[50]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which rotation constraints are active
el.offsets[3].value = Vector(( float(rw[51]), float(rw[52]), float(rw[53]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which angular velocity constraints are active
el.offsets[4].value = Vector(( float(rw[54]), float(rw[55]), float(rw[56]) ))
# FIXME: this is here to enhance backwards compatibility.
# should disappear in future versions
el.mbclass = 'elem.joint'
if el.name in bpy.data.objects.keys():
el.blender_object = el.name
except KeyError:
el = ed.add()
el.mbclass = 'elem.joint'
el.type = 'total_pin_joint'
el.int_label = int(rw[1])
eldbmsg({'PARSE_ELEM'}, "BLENDYN::parse_total_pin():", el)
eldbmsg({'NOTFOUND_DICT'}, "BLENDYN::parse_total_pin():", el)
el.nodes.add()
el.nodes[0].int_label = int(rw[2])
el.offsets.add()
el.offsets[0].value = Vector(( float(rw[3]), float(rw[4]), float(rw[5]) ))
el.rotoffsets.add()
R1p = Matrix().to_3x3()
parse_rotmat(rw, 6, R1p)
el.rotoffsets[0].value = R1p.to_quaternion();
el.rotoffsets.add()
R1r = Matrix().to_3x3()
parse_rotmat(rw, 15, R1p)
el.rotoffsets[1].value = R1r.to_quaternion();
# NOTE: This is not really an offset, but a bool vector
# indicating the position constraints that are active
el.offsets.add()
el.offsets[1].value = Vector(( float(rw[45]), float(rw[46]), float(rw[47]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which velocity constraints are active
el.offsets.add()
el.offsets[2].value = Vector(( float(rw[48]), float(rw[49]), float(rw[50]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which rotation constraints are active
el.offsets.add()
el.offsets[3].value = Vector(( float(rw[51]), float(rw[52]), float(rw[53]) ))
# NOTE: This is not really an offset, but a bool vector
# indicating which angular velocity constraints are active
el.offsets.add()
el.offsets[4].value = Vector(( float(rw[54]), float(rw[55]), float(rw[56]) ))
el.import_function = "blendyn.import_total_pin"
el.info_draw = "total_pin_info_draw"
el.name = el.type + "_" + str(el.int_label)
el.is_imported = True
ret_val = False
pass
return ret_val
# -----------------------------------------------------------
# end of parse_total_pin(rw, ed) function
def spawn_total_joint_element(elem, context):
""" Draws a total joint element, loading a wireframe
object from the addon library """
mbs = context.scene.mbdyn
nd = mbs.nodes
if any(obj == elem.blender_object for obj in context.scene.objects.keys()):
return {'OBJECT_EXISTS'}
try:
n1 = nd['node_' + str(elem.nodes[0].int_label)].blender_object
except KeyError:
return {'NODE1_NOTFOUND'}
try:
n2 = nd['node_' + str(elem.nodes[1].int_label)].blender_object
except KeyError:
return {'NODE2_NOTFOUND'}
# nodes' objects
n1OBJ = bpy.data.objects[n1]
n2OBJ = bpy.data.objects[n2]
# rotation quaternion and matrices, and position offsets
q1 = n1OBJ.rotation_quaternion
q2 = n2OBJ.rotation_quaternion
R1 = n1OBJ.rotation_quaternion.to_matrix()
R2 = n2OBJ.rotation_quaternion.to_matrix()
fP1 = elem.offsets[0].value
fP2 = elem.offsets[1].value
try:
set_active_collection('joints')
elcol = bpy.data.collections.new(name = elem.name)
bpy.data.collections['joints'].children.link(elcol)
set_active_collection(elcol.name)
# load the wireframe total joint object from the library
lib_path = os.path.join(mbs.addon_path, 'library', 'joints.blend', 'Object')
bpy.ops.wm.append(directory = lib_path, filename = 'total')
# the append operator leaves just the imported object selected
totjOBJ = bpy.context.selected_objects[0]
totjOBJ.name = elem.name
# place the joint object in the position defined relative to node 1
totjOBJ.location = n1OBJ.location + R1@Vector(( fP1[0], fP1[1], fP1[2] ))
totjOBJ.rotation_mode = 'QUATERNION'
totjOBJ.rotation_quaternion = Quaternion(elem.rotoffsets[0].value[0:])@q1
OBJs = list()
OBJs.append(totjOBJ);
# display traslation arrows
pos = ['total.disp.x', 'total.disp.y', 'total.disp.z']
for kk in range(3):
if not(elem.offsets[2].value[kk]):
app_retval = bpy.ops.wm.append(directory = lib_path, filename = pos[kk])
if app_retval != {'FINISHED'}:
return {'LIBRARY_ERROR'}
obj = bpy.context.selected_objects[0]
OBJs.append(obj)
# position it correctly, in global frame
obj.location = n1OBJ.location + R1@Vector(( fP1[0], fP1[1], fP1[2] ))
# rotate it according to "position orientation" w.r.t. node 1
obj.rotation_mode = 'QUATERNION'
obj.rotation_quaternion = Quaternion(elem.rotoffsets[0].value[0:])@q1
# display rotation arrows
rot = ['total.rot.x', 'total.rot.y', 'total.rot.z']
for kk in range(3):
if not(elem.offsets[4].value[kk]):
app_retval = bpy.ops.wm.append(directory = lib_path, filename = rot[kk])
if app_retval != {'FINISHED'}:
return {'LIBRARY_ERROR'}
obj = bpy.context.selected_objects[0]
OBJs.append(obj)
# position it correctly
obj.location = n1OBJ.location +R1@Vector(( elem.offsets[0].value[0:] ))
# rotate it according to "rotation orientation" w.r.t. node 1
obj.rotation_mode = 'QUATERNION'
obj.rotation_quaternion = Quaternion(elem.rotoffsets[1].value[0:])@q1
# TODO: display also velocity contraints arrows
# join objects, with context override
ctx = context.copy()
ctx['active_object'] = OBJs[0]
ctx['selected_editable_objects'] = OBJs
if bpy.app.version < (4, 0, 0):
bpy.ops.object.join(ctx)
else:
with context.temp_override(**ctx):
bpy.ops.object.join()
# automatic scaling
s = (.5/sqrt(3.))*(n1OBJ.scale.magnitude + n2OBJ.scale.magnitude)
totjOBJ.scale = Vector(( s, s, s ))
# create an object representing the RF used to express the relative
# position w.r.t. node 1, for model debuggingi
RF1p = bpy.data.objects.new(totjOBJ.name + '_RF1_pos', None)
RF1p.location = totjOBJ.location
RF1p.empty_display_type = 'ARROWS'
RF1p.rotation_mode = 'QUATERNION'
RF1p.rotation_quaternion = Quaternion(elem.rotoffsets[0].value[0:])@q1
# create an object representing the RF used to express the relative
# orientation w.r.t. node 1, for model debugging
RF1r = bpy.data.objects.new(totjOBJ.name + '_RF1_rot', None)
RF1r.location = totjOBJ.location
RF1r.empty_display_type = 'ARROWS'
RF1r.rotation_mode = 'QUATERNION'
RF1r.rotation_quaternion = Quaternion(elem.rotoffsets[1].value[0:])@q1
# create an object representing the RF used to express the relative
# position w.r.t. node 2, for model debugging
RF2p = bpy.data.objects.new(totjOBJ.name + '_RF2_pos', None)
RF2p.location = totjOBJ.location
RF2p.empty_display_type = 'ARROWS'
RF2p.rotation_mode = 'QUATERNION'
RF2p.rotation_quaternion = Quaternion(elem.rotoffsets[2].value[0:])@q2
# create an object representing the RF used to express the relative
# orientation w.r.t. node 2, for model debugging
RF2r = bpy.data.objects.new(totjOBJ.name + '_RF2_rot', None)
RF2r.location = totjOBJ.location
RF2r.empty_display_type = 'ARROWS'
RF2r.rotation_mode = 'QUATERNION'
RF2r.rotation_quaternion = Quaternion(elem.rotoffsets[3].value[0:])@q2
# set mbdyn props of object
elem.blender_object = totjOBJ.name
totjOBJ.mbdyn.dkey = elem.name
totjOBJ.mbdyn.type = 'element'
# set parenting of wireframe obj
parenting(totjOBJ, n1OBJ)
# parent the RF objects to the corresponding nodes
parenting(RF1p, n1OBJ)
parenting(RF1r, n1OBJ)
parenting(RF2p, n2OBJ)
parenting(RF2r, n2OBJ)
# link objects to element collection
elcol.objects.link(RF1p)
elcol.objects.link(RF1r)
elcol.objects.link(RF2p)
elcol.objects.link(RF2r)
RF1p.hide_set(state = True)
RF1r.hide_set(state = True)
RF2p.hide_set(state = True)
RF2r.hide_set(state = True)
elcol.objects.link(n1OBJ)
elcol.objects.link(n2OBJ)
set_active_collection('Master Collection')
return {'FINISHED'}
except FileNotFoundError:
return {'LIBRARY_ERROR'}
except KeyError:
return {'COLLECTION_ERROR'}
# -----------------------------------------------------------
# end of spawn_total(elem, context) function
def spawn_total_pin_joint_element(elem, context):
""" Draws a total pin joint element, loading a wireframe
object from the addon library """
mbs = context.scene.mbdyn
nd = mbs.nodes
if any(obj == elem.blender_object for obj in context.scene.objects.keys()):
return {'OBJECT_EXISTS'}
try:
n1 = nd['node_' + str(elem.nodes[0].int_label)].blender_object
except KeyError:
return {'NODE1_NOTFOUND'}
# nodes' objects
n1OBJ = bpy.data.objects[n1]
try:
set_active_collection('joints')
elcol = bpy.data.collections.new(name = elem.name)
bpy.data.collections['joints'].children.link(elcol)
set_active_collection(elcol.name)
# load the wireframe total joint object from the library
lib_path = os.path.join(mbs.addon_path,\
'library', 'joints.blend', 'Object')
bpy.ops.wm.append(directory = lib_path, filename = 'total.pin')
# the append operator leaves just the imported object selected
totjOBJ = bpy.context.selected_objects[0]
totjOBJ.name = elem.name
# place the joint object in the position defined relative to node 1
totjOBJ.location = elem.offsets[0].value
totjOBJ.rotation_mode = 'QUATERNION'
totjOBJ.rotation_quaternion = Quaternion(elem.rotoffsets[0].value)
OBJs = list()
OBJs.append(totjOBJ)
# display traslation arrows
pos = ['total.disp.x', 'total.disp.y', 'total.disp.z']
for kk in range(3):
if not(elem.offsets[1].value[kk]):
app_retval = bpy.ops.wm.append(directory = lib_path, filename = pos[kk])
if app_retval != {'FINISHED'}:
return {'LIBRARY_ERROR'}
obj = bpy.context.selected_objects[0]
OBJs.append(obj)
# position it correctly
obj.location = elem.offsets[0].value
# rotate it according to "position orientation" w.r.t. node 1
obj.rotation_mode = 'QUATERNION'
obj.rotation_quaternion = Quaternion(elem.rotoffsets[0].value)
# display rotation arrows
rot = ['total.rot.x', 'total.rot.y', 'total.rot.z']
for kk in range(3):
if not(elem.offsets[3].value[kk]):
app_retval = bpy.ops.wm.append(directory = lib_path, filename = rot[kk])
if app_retval != {'FINISHED'}:
return {'LIBRARY_ERROR'}
obj = bpy.context.selected_objects[0]
OBJs.append(obj)
# position it correctly
obj.location = elem.offsets[0].value
# rotate it according to "rotation orientation" w.r.t. node 1
obj.rotation_mode = 'QUATERNION'
obj.rotation_quaternion = Quaternion(elem.rotoffsets[0].value)
# TODO: display also velocity contraints arrows
# join objects, with context override
ctx = context.copy()
ctx['active_object'] = OBJs[0]
ctx['selected_editable_objects'] = OBJs
if bpy.app.version < (4, 0, 0):
bpy.ops.object.join(ctx)
else:
with context.temp_override(**ctx):
bpy.ops.object.join()
# automatic scaling
s = (.5/sqrt(3.))*n1OBJ.scale.magnitude
totjOBJ.scale = Vector(( s, s, s ))
# create an object representing the RF used to express the relative
# position w.r.t. node 1, for model debugging
RF1p = bpy.data.objects.new(totjOBJ.name + '_RF1_pos', None)
RF1p.empty_display_type = 'ARROWS'
RF1p.rotation_mode = 'QUATERNION'
RF1p.rotation_quaternion = Quaternion(elem.rotoffsets[0].value)
# create an object representing the RF used to express the relative
# orientation w.r.t. node 1, for model debugging
RF1r = bpy.data.objects.new(totjOBJ.name + '_RF1_rot', None)
RF1r.empty_display_type = 'ARROWS'
RF1r.rotation_mode = 'QUATERNION'
RF1r.rotation_quaternion = Quaternion(elem.rotoffsets[1].value)
# set parenting of wireframe obj
parenting(totjOBJ, n1OBJ)
# set parenting of RF objects
parenting(RF1p, n1OBJ)
parenting(RF1r, n1OBJ)
# set objects' mbdyn props
elem.blender_object = totjOBJ.name
totjOBJ.mbdyn.dkey = elem.name
totjOBJ.mbdyn.type = 'element'
# link objects to element collection
elcol.objects.link(n1OBJ)
elcol.objects.link(RF1p)
elcol.objects.link(RF1r)
RF1p.hide_set(state = True)
RF1r.hide_set(state = True)
set_active_collection('Master Collection')
return {'FINISHED'}
except FileNotFoundError:
return {'LIBRARY_ERROR'}
except KeyError:
return {'COLLECTION_ERROR'}
# -----------------------------------------------------------
# end of spawn_total_pin_joint_element(elem, context) function
def total_info_draw(elem, layout):
""" Displays total joint infos in the tools panel """
nd = bpy.context.scene.mbdyn.nodes
row = layout.row()
col = layout.column(align = True)
for node in nd:
if node.int_label == elem.nodes[0].int_label:
# Display node 1 info
col.prop(node, "int_label", text = "Node 1 ID ")
col.prop(node, "string_label", text = "Node 1 label ")
col.prop(node, "blender_object", text = "Node 1 Object: ")
col.enabled = False
# Display offset from node 1
row = layout.row()
row.label(text = "offset 1 in node 1 R.F.")
col = layout.column(align = True)
col.prop(elem.offsets[0], "value", text = "", slider = False)
# Display position orientation - node 1
row = layout.row()
row.label(text = "pos. orientation node 1 R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[0], "value", text = "", slider = False)
# Display rotation orientation - node 1
row = layout.row()
row.label(text = "rot. orientation node 1 R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[1], "value", text = "", slider = False)
layout.separator()
elif node.int_label == elem.nodes[1].int_label:
# Display node 2 info
col.prop(node, "int_label", text = "Node 2 ID ")
col.prop(node, "string_label", text = "Node 2 label ")
col.prop(node, "blender_object", text = "Node 2 Object: ")
col.enabled = False
# Display offset from node 2
row = layout.row()
row.label(text = "offset 2 in node 2 R.F.")
col = layout.column(align = True)
col.prop(elem.offsets[1], "value", text = "", slider = False)
# Display position orientation - node 2
row = layout.row()
row.label(text = "pos. orientation node 2 R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[2], "value", text = "", slider = False)
# Display rotation orientation - node 2
row = layout.row()
row.label(text = "rot. orientation node 2 R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[3], "value", text = "", slider = False)
layout.separator()
# Display total joint active components
box = layout.box()
split = box.split(1./8.)
# position
column = split.column()
column.row().label(text = "pos.X:")
column.row().label(text = "pos.Y:")
column.row().label(text = "pos.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[2].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# linear velocity
column = split.column()
column.row().label(text = "vel.X:")
column.row().label(text = "vel.Y:")
column.row().label(text = "vel.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[3].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# rotation
column = split.column()
column.row().label(text = "rot.X:")
column.row().label(text = "rot.Y:")
column.row().label(text = "rot.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[4].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# angular velocity
column = split.column()
column.row().label(text = "angvel.X:")
column.row().label(text = "angvel.Y:")
column.row().label(text = "angvel.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[5].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# -----------------------------------------------------------
# end of total_info_draw(elem, layout) function
def total_pin_info_draw(elem, layout):
""" Displays total pin joint infos in the tools panel """
nd = bpy.context.scene.mbdyn.nodes
row = layout.row()
col = layout.column(align=True)
for node in nd:
if node.int_label == elem.nodes[0].int_label:
# Display node 1 info
col.prop(node, "int_label", text = "Node 1 ID ")
col.prop(node, "string_label", text = "Node 1 label ")
col.prop(node, "blender_object", text = "Node 1 Object: ")
col.enabled = False
# Display offset from node 1
row = layout.row()
row.label(text = "offset 1 in node R.F.")
col = layout.column(align = True)
col.prop(elem.offsets[0], "value", text = "", slider = False)
# Display position orientation - node 1
row = layout.row()
row.label(text = "pos. orientation node R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[0], "value", text = "", slider = False)
# Display rotation orientation - node 1
row = layout.row()
row.label(text = "rot. orientation node R.F.")
col = layout.column(align = True)
col.prop(elem.rotoffsets[1], "value", text = "", slider = False)
layout.separator()
# Display total joint active components
box = layout.box()
split = box.split(1./8.)
# position
column = split.column()
column.row().label(text = "pos.X:")
column.row().label(text = "pos.Y:")
column.row().label(text = "pos.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[1].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# linear velocity
column = split.column()
column.row().label(text = "vel.X:")
column.row().label(text = "vel.Y:")
column.row().label(text = "vel.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[2].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# rotation
column = split.column()
column.row().label(text = "rot.X:")
column.row().label(text = "rot.Y:")
column.row().label(text = "rot.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[3].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
# angular velocity
column = split.column()
column.row().label(text = "angvel.X:")
column.row().label(text = "angvel.Y:")
column.row().label(text = "angvel.Z:")
column = split.column()
for kk in range(3):
if elem.offsets[4].value[kk]:
column.row().label(text = "active")
else:
column.row().label(text = "inactive")
pass
# -----------------------------------------------------------
# end of totpinj_info_draw(elem, layout) function
class BLENDYN_OT_import_total(bpy.types.Operator):
""" Imports a total joint element into the Blender scene """
bl_idname = "blendyn.import_total"
bl_label = "Imports a total joint element"
int_label: bpy.props.IntProperty()
def draw(self, context):
layout = self.layout
layout.alignment = 'LEFT'
def execute(self, context):
ed = bpy.context.scene.mbdyn.elems
nd = bpy.context.scene.mbdyn.nodes
try:
elem = ed['total_joint_' + str(self.int_label)]
retval = spawn_total_joint_element(elem, context)
if retval == {'OBJECT_EXISTS'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'NODE1_NOTFOUND'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'NODE2_NOTFOUND'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'COLLECTION_ERROR'}:
eldbmsf(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'LIBRARY_ERROR'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'FINISHED'}:
eldbmsg({'IMPORT_SUCCESS'}, type(self).__name__ + '::execute()', elem)
return retval
else:
# Should not be reached
return retval
except KeyError:
eldbmsg({'DICT_ERROR'}, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
# -----------------------------------------------------------
# end of BLENDYN_OT_import_total class
class BLENDYN_OT_import_total_pin(bpy.types.Operator):
""" Imports a total joint element into the Blender scene"""
bl_idname = "blendyn.import_total_pin"
bl_label = "Imports a total joint element"
int_label: bpy.props.IntProperty()
def draw(self, context):
layout = self.layout
layout.alignment = 'LEFT'
def execute(self, context):
ed = bpy.context.scene.mbdyn.elems
nd = bpy.context.scene.mbdyn.nodes
try:
elem = ed['total_pin_joint_' + str(self.int_label)]
retval = spawn_total_pin_joint_element(elem, context)
if retval == {'OBJECT_EXISTS'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'NODE1_NOTFOUND'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'COLLECTION_ERROR'}:
eldbmsf(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'LIBRARY_ERROR'}:
eldbmsg(retval, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
elif retval == {'FINISHED'}:
eldbmsg({'IMPORT_SUCCESS'}, type(self).__name__ + '::execute()', elem)
return retval
else:
# Should not be reached
return retval
except KeyError:
eldbmsg({'DICT_ERROR'}, type(self).__name__ + '::execute()', elem)
return {'CANCELLED'}
# -----------------------------------------------------------
# end of BLENDYN_OT_import_total_pin class