/
Mjt.swift
1323 lines (1323 loc) · 26.6 KB
/
Mjt.swift
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
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// warning types
@objc
public enum MjtWarning: Int32, CustomStringConvertible, CaseIterable {
case inertia = 0
case contactfull
case cnstrfull
case vgeomfull
case badqpos
case badqvel
case badqacc
case badctrl
public var description: String {
switch self {
case .inertia:
return "inertia"
case .contactfull:
return "contactfull"
case .cnstrfull:
return "cnstrfull"
case .vgeomfull:
return "vgeomfull"
case .badqpos:
return "badqpos"
case .badqvel:
return "badqvel"
case .badqacc:
return "badqacc"
case .badctrl:
return "badctrl"
}
}
}
@objc
public enum MjtTimer: Int32, CustomStringConvertible, CaseIterable {
case step = 0
case forward
case inverse
case position
case velocity
case actuation
case acceleration
case constraint
case posKinematics
case posInertia
case posCollision
case posMake
case posProject
public var description: String {
switch self {
case .step:
return "step"
case .forward:
return "forward"
case .inverse:
return "inverse"
case .position:
return "position"
case .velocity:
return "velocity"
case .actuation:
return "actuation"
case .acceleration:
return "acceleration"
case .constraint:
return "constraint"
case .posKinematics:
return "posKinematics"
case .posInertia:
return "posInertia"
case .posCollision:
return "posCollision"
case .posMake:
return "posMake"
case .posProject:
return "posProject"
}
}
}
/// disable default feature bitflags
public struct MjtDisableBit: OptionSet, CustomStringConvertible, CaseIterable {
public let rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public static let constraint = MjtDisableBit(rawValue: 1 << 0)
public static let equality = MjtDisableBit(rawValue: 1 << 1)
public static let frictionloss = MjtDisableBit(rawValue: 1 << 2)
public static let limit = MjtDisableBit(rawValue: 1 << 3)
public static let contact = MjtDisableBit(rawValue: 1 << 4)
public static let passive = MjtDisableBit(rawValue: 1 << 5)
public static let gravity = MjtDisableBit(rawValue: 1 << 6)
public static let clampctrl = MjtDisableBit(rawValue: 1 << 7)
public static let warmstart = MjtDisableBit(rawValue: 1 << 8)
public static let filterparent = MjtDisableBit(rawValue: 1 << 9)
public static let actuation = MjtDisableBit(rawValue: 1 << 10)
public static let refsafe = MjtDisableBit(rawValue: 1 << 11)
public static let sensor = MjtDisableBit(rawValue: 1 << 12)
public static let allCases: [MjtDisableBit] = [
.constraint, .equality, .frictionloss, .limit, .contact, .passive, .gravity, .clampctrl,
.warmstart, .filterparent, .actuation, .refsafe, .sensor,
]
public var description: String {
switch self {
case .constraint:
return "constraint"
case .equality:
return "equality"
case .frictionloss:
return "frictionloss"
case .limit:
return "limit"
case .contact:
return "contact"
case .passive:
return "passive"
case .gravity:
return "gravity"
case .clampctrl:
return "clampctrl"
case .warmstart:
return "warmstart"
case .filterparent:
return "filterparent"
case .actuation:
return "actuation"
case .refsafe:
return "refsafe"
case .sensor:
return "sensor"
default:
return "MjtDisableBit(rawValue: \(rawValue))"
}
}
}
/// enable optional feature bitflags
public struct MjtEnableBit: OptionSet, CustomStringConvertible, CaseIterable {
public let rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public static let override = MjtEnableBit(rawValue: 1 << 0)
public static let energy = MjtEnableBit(rawValue: 1 << 1)
public static let fwdinv = MjtEnableBit(rawValue: 1 << 2)
public static let sensornoise = MjtEnableBit(rawValue: 1 << 3)
public static let multiccd = MjtEnableBit(rawValue: 1 << 4)
public static let allCases: [MjtEnableBit] = [
.override, .energy, .fwdinv, .sensornoise, .multiccd,
]
public var description: String {
switch self {
case .override:
return "override"
case .energy:
return "energy"
case .fwdinv:
return "fwdinv"
case .sensornoise:
return "sensornoise"
case .multiccd:
return "multiccd"
default:
return "MjtEnableBit(rawValue: \(rawValue))"
}
}
}
/// type of degree of freedom
@objc
public enum MjtJoint: Int32, CustomStringConvertible {
case free = 0
case ball
case slide
case hinge
public var description: String {
switch self {
case .free:
return "free"
case .ball:
return "ball"
case .slide:
return "slide"
case .hinge:
return "hinge"
}
}
}
/// type of geometric shape
@objc
public enum MjtGeom: Int32, CustomStringConvertible, CaseIterable {
case plane = 0
case hfield
case sphere
case capsule
case ellipsoid
case cylinder
case box
case mesh
case arrow = 100
case arrow1
case arrow2
case line
case skin
case label
case none = 1001
public var description: String {
switch self {
case .plane:
return "plane"
case .hfield:
return "hfield"
case .sphere:
return "sphere"
case .capsule:
return "capsule"
case .ellipsoid:
return "ellipsoid"
case .cylinder:
return "cylinder"
case .box:
return "box"
case .mesh:
return "mesh"
case .arrow:
return "arrow"
case .arrow1:
return "arrow1"
case .arrow2:
return "arrow2"
case .line:
return "line"
case .skin:
return "skin"
case .label:
return "label"
case .none:
return "none"
}
}
}
/// tracking mode for camera and light
@objc
public enum MjtCamLight: Int32, CustomStringConvertible {
case fixed = 0
case track
case trackcom
case targetbody
case targetbodycom
public var description: String {
switch self {
case .fixed:
return "fixed"
case .track:
return "track"
case .trackcom:
return "trackcom"
case .targetbody:
return "targetbody"
case .targetbodycom:
return "targetbodycom"
}
}
}
/// type of texture
@objc
public enum MjtTexture: Int32, CustomStringConvertible {
case _2d = 0
case cube
case skybox
public var description: String {
switch self {
case ._2d:
return "_2d"
case .cube:
return "cube"
case .skybox:
return "skybox"
}
}
}
/// integrator mode
@objc
public enum MjtIntegrator: Int32, CustomStringConvertible {
case euler = 0
case rk4
case implicit
public var description: String {
switch self {
case .euler:
return "euler"
case .rk4:
return "rk4"
case .implicit:
return "implicit"
}
}
}
/// collision mode for selecting geom pairs
@objc
public enum MjtCollision: Int32, CustomStringConvertible {
case all = 0
case pair
case `dynamic`
public var description: String {
switch self {
case .all:
return "all"
case .pair:
return "pair"
case .`dynamic`:
return "dynamic"
}
}
}
/// type of friction cone
@objc
public enum MjtCone: Int32, CustomStringConvertible {
case pyramidal = 0
case elliptic
public var description: String {
switch self {
case .pyramidal:
return "pyramidal"
case .elliptic:
return "elliptic"
}
}
}
/// type of constraint Jacobian
@objc
public enum MjtJacobian: Int32, CustomStringConvertible {
case dense = 0
case sparse
case auto
public var description: String {
switch self {
case .dense:
return "dense"
case .sparse:
return "sparse"
case .auto:
return "auto"
}
}
}
/// constraint solver algorithm
@objc
public enum MjtSolver: Int32, CustomStringConvertible {
case pgs = 0
case cg
case newton
public var description: String {
switch self {
case .pgs:
return "pgs"
case .cg:
return "cg"
case .newton:
return "newton"
}
}
}
/// type of equality constraint
@objc
public enum MjtEq: Int32, CustomStringConvertible {
case connect = 0
case weld
case joint
case tendon
case distance
public var description: String {
switch self {
case .connect:
return "connect"
case .weld:
return "weld"
case .joint:
return "joint"
case .tendon:
return "tendon"
case .distance:
return "distance"
}
}
}
/// type of tendon wrap object
@objc
public enum MjtWrap: Int32, CustomStringConvertible {
case none = 0
case joint
case pulley
case site
case sphere
case cylinder
public var description: String {
switch self {
case .none:
return "none"
case .joint:
return "joint"
case .pulley:
return "pulley"
case .site:
return "site"
case .sphere:
return "sphere"
case .cylinder:
return "cylinder"
}
}
}
/// type of actuator transmission
@objc
public enum MjtTrn: Int32, CustomStringConvertible {
case joint = 0
case jointinparent
case slidercrank
case tendon
case site
case body
case undefined = 1000
public var description: String {
switch self {
case .joint:
return "joint"
case .jointinparent:
return "jointinparent"
case .slidercrank:
return "slidercrank"
case .tendon:
return "tendon"
case .site:
return "site"
case .body:
return "body"
case .undefined:
return "undefined"
}
}
}
/// type of actuator dynamics
@objc
public enum MjtDyn: Int32, CustomStringConvertible {
case none = 0
case integrator
case filter
case muscle
case user
public var description: String {
switch self {
case .none:
return "none"
case .integrator:
return "integrator"
case .filter:
return "filter"
case .muscle:
return "muscle"
case .user:
return "user"
}
}
}
/// type of actuator gain
@objc
public enum MjtGain: Int32, CustomStringConvertible {
case fixed = 0
case affine
case muscle
case user
public var description: String {
switch self {
case .fixed:
return "fixed"
case .affine:
return "affine"
case .muscle:
return "muscle"
case .user:
return "user"
}
}
}
/// type of actuator bias
@objc
public enum MjtBias: Int32, CustomStringConvertible {
case none = 0
case affine
case muscle
case user
public var description: String {
switch self {
case .none:
return "none"
case .affine:
return "affine"
case .muscle:
return "muscle"
case .user:
return "user"
}
}
}
/// type of MujoCo object
@objc
public enum MjtObj: Int32, CustomStringConvertible {
case unknown = 0
case body
case xbody
case joint
case dof
case geom
case site
case camera
case light
case mesh
case skin
case hfield
case texture
case material
case pair
case exclude
case equality
case tendon
case actuator
case sensor
case numeric
case text
case tuple
case key
case plugin
public var description: String {
switch self {
case .unknown:
return "unknown"
case .body:
return "body"
case .xbody:
return "xbody"
case .joint:
return "joint"
case .dof:
return "dof"
case .geom:
return "geom"
case .site:
return "site"
case .camera:
return "camera"
case .light:
return "light"
case .mesh:
return "mesh"
case .skin:
return "skin"
case .hfield:
return "hfield"
case .texture:
return "texture"
case .material:
return "material"
case .pair:
return "pair"
case .exclude:
return "exclude"
case .equality:
return "equality"
case .tendon:
return "tendon"
case .actuator:
return "actuator"
case .sensor:
return "sensor"
case .numeric:
return "numeric"
case .text:
return "text"
case .tuple:
return "tuple"
case .key:
return "key"
case .plugin:
return "plugin"
}
}
}
/// type of constraint
@objc
public enum MjtConstraint: Int32, CustomStringConvertible {
case equality = 0
case frictionDof
case frictionTendon
case limitJoint
case limitTendon
case contactFrictionless
case contactPyramidal
case contactElliptic
public var description: String {
switch self {
case .equality:
return "equality"
case .frictionDof:
return "frictionDof"
case .frictionTendon:
return "frictionTendon"
case .limitJoint:
return "limitJoint"
case .limitTendon:
return "limitTendon"
case .contactFrictionless:
return "contactFrictionless"
case .contactPyramidal:
return "contactPyramidal"
case .contactElliptic:
return "contactElliptic"
}
}
}
/// constraint state
@objc
public enum MjtConstraintState: Int32, CustomStringConvertible {
case satisfied = 0
case quadratic
case linearneg
case linearpos
case cone
public var description: String {
switch self {
case .satisfied:
return "satisfied"
case .quadratic:
return "quadratic"
case .linearneg:
return "linearneg"
case .linearpos:
return "linearpos"
case .cone:
return "cone"
}
}
}
/// type of sensor
@objc
public enum MjtSensor: Int32, CustomStringConvertible {
case touch = 0
case accelerometer
case velocimeter
case gyro
case force
case torque
case magnetometer
case rangefinder
case jointpos
case jointvel
case tendonpos
case tendonvel
case actuatorpos
case actuatorvel
case actuatorfrc
case ballquat
case ballangvel
case jointlimitpos
case jointlimitvel
case jointlimitfrc
case tendonlimitpos
case tendonlimitvel
case tendonlimitfrc
case framepos
case framequat
case framexaxis
case frameyaxis
case framezaxis
case framelinvel
case frameangvel
case framelinacc
case frameangacc
case subtreecom
case subtreelinvel
case subtreeangmom
case clock
case plugin
case user
public var description: String {
switch self {
case .touch:
return "touch"
case .accelerometer:
return "accelerometer"
case .velocimeter:
return "velocimeter"
case .gyro:
return "gyro"
case .force:
return "force"
case .torque:
return "torque"
case .magnetometer:
return "magnetometer"
case .rangefinder:
return "rangefinder"
case .jointpos:
return "jointpos"
case .jointvel:
return "jointvel"
case .tendonpos:
return "tendonpos"
case .tendonvel:
return "tendonvel"
case .actuatorpos:
return "actuatorpos"
case .actuatorvel:
return "actuatorvel"
case .actuatorfrc:
return "actuatorfrc"
case .ballquat:
return "ballquat"
case .ballangvel:
return "ballangvel"
case .jointlimitpos:
return "jointlimitpos"
case .jointlimitvel:
return "jointlimitvel"
case .jointlimitfrc:
return "jointlimitfrc"
case .tendonlimitpos:
return "tendonlimitpos"
case .tendonlimitvel:
return "tendonlimitvel"
case .tendonlimitfrc:
return "tendonlimitfrc"
case .framepos:
return "framepos"
case .framequat:
return "framequat"
case .framexaxis:
return "framexaxis"
case .frameyaxis:
return "frameyaxis"
case .framezaxis:
return "framezaxis"
case .framelinvel:
return "framelinvel"
case .frameangvel:
return "frameangvel"
case .framelinacc:
return "framelinacc"
case .frameangacc:
return "frameangacc"
case .subtreecom:
return "subtreecom"
case .subtreelinvel:
return "subtreelinvel"
case .subtreeangmom:
return "subtreeangmom"
case .clock:
return "clock"
case .plugin:
return "plugin"
case .user:
return "user"
}
}
}
/// computation stage
@objc
public enum MjtStage: Int32, CustomStringConvertible {
case none = 0
case pos
case vel
case acc
public var description: String {
switch self {
case .none:
return "none"
case .pos:
return "pos"
case .vel:
return "vel"
case .acc:
return "acc"
}
}
}
/// data type for sensors
@objc
public enum MjtDataType: Int32, CustomStringConvertible {
case real = 0
case positive
case axis
case quaternion
public var description: String {
switch self {
case .real:
return "real"
case .positive:
return "positive"
case .axis:
return "axis"
case .quaternion:
return "quaternion"
}
}
}
/// mode for actuator length range computation
@objc
public enum MjtLRMode: Int32, CustomStringConvertible {
case none = 0
case muscle
case muscleuser
case all
public var description: String {
switch self {
case .none:
return "none"
case .muscle:
return "muscle"
case .muscleuser:
return "muscleuser"
case .all:
return "all"
}
}
}
@objc
public enum MjtPluginTypeBit: Int32, CustomStringConvertible {
case actuator = 1
case sensor = 2
case passive = 4
public var description: String {
switch self {
case .actuator:
return "actuator"
case .sensor:
return "sensor"
case .passive:
return "passive"
}
}
}
/// grid position for overlay
@objc
public enum MjtGridPos: Int32, CustomStringConvertible {
case topleft = 0
case topright
case bottomleft
case bottomright
public var description: String {
switch self {
case .topleft:
return "topleft"
case .topright:
return "topright"
case .bottomleft:
return "bottomleft"
case .bottomright:
return "bottomright"
}
}
}
/// OpenGL framebuffer option
@objc
public enum MjtFramebuffer: Int32, CustomStringConvertible {
case window = 0
case offscreen
public var description: String {
switch self {
case .window:
return "window"
case .offscreen:
return "offscreen"
}
}
}
/// font scale, used at context creation
@objc
public enum MjtFontScale: Int32, CustomStringConvertible {
case _50 = 50
case _100 = 100
case _150 = 150
case _200 = 200
case _250 = 250
case _300 = 300
public var description: String {
switch self {
case ._50:
return "_50"
case ._100:
return "_100"
case ._150:
return "_150"
case ._200:
return "_200"
case ._250:
return "_250"
case ._300:
return "_300"
}
}
}
/// font type, used at each text operation
@objc
public enum MjtFont: Int32, CustomStringConvertible {
case normal = 0
case shadow
case big
public var description: String {
switch self {
case .normal:
return "normal"
case .shadow:
return "shadow"
case .big:
return "big"
}
}
}
/// mouse button
@objc
public enum MjtButton: Int32, CustomStringConvertible {
case none = 0
case left
case right
case middle
public var description: String {
switch self {
case .none:
return "none"
case .left:
return "left"
case .right:
return "right"
case .middle:
return "middle"
}
}
}
/// mouse and keyboard event type
@objc
public enum MjtEvent: Int32, CustomStringConvertible {
case none = 0
case move
case press
case release
case scroll
case key
case resize
public var description: String {
switch self {
case .none:
return "none"
case .move:
return "move"
case .press:
return "press"
case .release:
return "release"
case .scroll:
return "scroll"
case .key:
return "key"
case .resize:
return "resize"
}
}
}
/// UI item type
@objc
public enum MjtItem: Int32, CustomStringConvertible, CaseIterable {
case end = -2
case section = -1
case separator = 0
case `static`
case button
case checkint
case checkbyte
case radio
case radioline
case select
case sliderint
case slidernum
case editint
case editnum
case edittxt
public var description: String {
switch self {
case .end:
return "end"
case .section:
return "section"
case .separator:
return "separator"
case .`static`:
return "static"
case .button:
return "button"
case .checkint:
return "checkint"
case .checkbyte:
return "checkbyte"
case .radio:
return "radio"
case .radioline: