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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
|
# Copyright 2018 The glTF-Blender-IO authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: Generated from latest glTF 2.0 JSON Scheme specs using quicktype (https://github.com/quicktype/quicktype)
# command used:
# quicktype --src glTF.schema.json --src-lang schema -t gltf --lang python --python-version 3.5
# TODO: add __slots__ to all classes by extending the generator
# TODO: REMOVE traceback import
import sys
import traceback
from io_scene_gltf2.io.com import gltf2_io_debug
def from_int(x):
assert isinstance(x, int) and not isinstance(x, bool)
return x
def from_none(x):
assert x is None
return x
def from_union(fs, x):
tracebacks = []
for f in fs:
try:
return f(x)
except AssertionError:
_, _, tb = sys.exc_info()
tracebacks.append(tb)
for tb in tracebacks:
traceback.print_tb(tb) # Fixed format
tb_info = traceback.extract_tb(tb)
for tbi in tb_info:
filename, line, func, text = tbi
gltf2_io_debug.print_console('ERROR', 'An error occurred on line {} in statement {}'.format(line, text))
assert False
def from_dict(f, x):
assert isinstance(x, dict)
return {k: f(v) for (k, v) in x.items()}
def to_class(c, x):
assert isinstance(x, c)
return x.to_dict()
def from_list(f, x):
assert isinstance(x, list)
return [f(y) for y in x]
def from_float(x):
assert isinstance(x, (float, int)) and not isinstance(x, bool)
return float(x)
def from_str(x):
assert isinstance(x, str)
return x
def from_bool(x):
assert isinstance(x, bool)
return x
def to_float(x):
assert isinstance(x, float)
return x
class AccessorSparseIndices:
"""Index array of size `count` that points to those accessor attributes that deviate from
their initialization value. Indices must strictly increase.
Indices of those attributes that deviate from their initialization value.
"""
def __init__(self, buffer_view, byte_offset, component_type, extensions, extras):
self.buffer_view = buffer_view
self.byte_offset = byte_offset
self.component_type = component_type
self.extensions = extensions
self.extras = extras
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
buffer_view = from_int(obj.get("bufferView"))
byte_offset = from_union([from_int, from_none], obj.get("byteOffset"))
component_type = from_int(obj.get("componentType"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
return AccessorSparseIndices(buffer_view, byte_offset, component_type, extensions, extras)
def to_dict(self):
result = {}
result["bufferView"] = from_int(self.buffer_view)
result["byteOffset"] = from_union([from_int, from_none], self.byte_offset)
result["componentType"] = from_int(self.component_type)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
return result
class AccessorSparseValues:
"""Array of size `count` times number of components, storing the displaced accessor
attributes pointed by `indices`. Substituted values must have the same `componentType`
and number of components as the base accessor.
Array of size `accessor.sparse.count` times number of components storing the displaced
accessor attributes pointed by `accessor.sparse.indices`.
"""
def __init__(self, buffer_view, byte_offset, extensions, extras):
self.buffer_view = buffer_view
self.byte_offset = byte_offset
self.extensions = extensions
self.extras = extras
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
buffer_view = from_int(obj.get("bufferView"))
byte_offset = from_union([from_int, from_none], obj.get("byteOffset"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
return AccessorSparseValues(buffer_view, byte_offset, extensions, extras)
def to_dict(self):
result = {}
result["bufferView"] = from_int(self.buffer_view)
result["byteOffset"] = from_union([from_int, from_none], self.byte_offset)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
return result
class AccessorSparse:
"""Sparse storage of attributes that deviate from their initialization value."""
def __init__(self, count, extensions, extras, indices, values):
self.count = count
self.extensions = extensions
self.extras = extras
self.indices = indices
self.values = values
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
count = from_int(obj.get("count"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
indices = AccessorSparseIndices.from_dict(obj.get("indices"))
values = AccessorSparseValues.from_dict(obj.get("values"))
return AccessorSparse(count, extensions, extras, indices, values)
def to_dict(self):
result = {}
result["count"] = from_int(self.count)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["indices"] = to_class(AccessorSparseIndices, self.indices)
result["values"] = to_class(AccessorSparseValues, self.values)
return result
class Accessor:
"""A typed view into a bufferView. A bufferView contains raw binary data. An accessor
provides a typed view into a bufferView or a subset of a bufferView similar to how
WebGL's `vertexAttribPointer()` defines an attribute in a buffer.
"""
def __init__(self, buffer_view, byte_offset, component_type, count, extensions, extras, max, min, name, normalized,
sparse, type):
self.buffer_view = buffer_view
self.byte_offset = byte_offset
self.component_type = component_type
self.count = count
self.extensions = extensions
self.extras = extras
self.max = max
self.min = min
self.name = name
self.normalized = normalized
self.sparse = sparse
self.type = type
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
buffer_view = from_union([from_int, from_none], obj.get("bufferView"))
byte_offset = from_union([from_int, from_none], obj.get("byteOffset"))
component_type = from_int(obj.get("componentType"))
count = from_int(obj.get("count"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
max = from_union([lambda x: from_list(from_float, x), from_none], obj.get("max"))
min = from_union([lambda x: from_list(from_float, x), from_none], obj.get("min"))
name = from_union([from_str, from_none], obj.get("name"))
normalized = from_union([from_bool, from_none], obj.get("normalized"))
sparse = from_union([AccessorSparse.from_dict, from_none], obj.get("sparse"))
type = from_str(obj.get("type"))
return Accessor(buffer_view, byte_offset, component_type, count, extensions, extras, max, min, name, normalized,
sparse, type)
def to_dict(self):
result = {}
result["bufferView"] = from_union([from_int, from_none], self.buffer_view)
result["byteOffset"] = from_union([from_int, from_none], self.byte_offset)
result["componentType"] = from_int(self.component_type)
result["count"] = from_int(self.count)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["max"] = from_union([lambda x: from_list(to_float, x), from_none], self.max)
result["min"] = from_union([lambda x: from_list(to_float, x), from_none], self.min)
result["name"] = from_union([from_str, from_none], self.name)
result["normalized"] = from_union([from_bool, from_none], self.normalized)
result["sparse"] = from_union([lambda x: to_class(AccessorSparse, x), from_none], self.sparse)
result["type"] = from_str(self.type)
return result
class AnimationChannelTarget:
"""The index of the node and TRS property to target.
The index of the node and TRS property that an animation channel targets.
"""
def __init__(self, extensions, extras, node, path):
self.extensions = extensions
self.extras = extras
self.node = node
self.path = path
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
node = from_union([from_int, from_none], obj.get("node"))
path = from_str(obj.get("path"))
return AnimationChannelTarget(extensions, extras, node, path)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["node"] = from_union([from_int, from_none], self.node)
result["path"] = from_str(self.path)
return result
class AnimationChannel:
"""Targets an animation's sampler at a node's property."""
def __init__(self, extensions, extras, sampler, target):
self.extensions = extensions
self.extras = extras
self.sampler = sampler
self.target = target
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
sampler = from_int(obj.get("sampler"))
target = AnimationChannelTarget.from_dict(obj.get("target"))
return AnimationChannel(extensions, extras, sampler, target)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["sampler"] = from_int(self.sampler)
result["target"] = to_class(AnimationChannelTarget, self.target)
return result
class AnimationSampler:
"""Combines input and output accessors with an interpolation algorithm to define a keyframe
graph (but not its target).
"""
def __init__(self, extensions, extras, input, interpolation, output):
self.extensions = extensions
self.extras = extras
self.input = input
self.interpolation = interpolation
self.output = output
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
input = from_int(obj.get("input"))
interpolation = from_union([from_str, from_none], obj.get("interpolation"))
output = from_int(obj.get("output"))
return AnimationSampler(extensions, extras, input, interpolation, output)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["input"] = from_int(self.input)
result["interpolation"] = from_union([from_str, from_none], self.interpolation)
result["output"] = from_int(self.output)
return result
class Animation:
"""A keyframe animation."""
def __init__(self, channels, extensions, extras, name, samplers):
self.channels = channels
self.extensions = extensions
self.extras = extras
self.name = name
self.samplers = samplers
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
channels = from_list(AnimationChannel.from_dict, obj.get("channels"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
samplers = from_list(AnimationSampler.from_dict, obj.get("samplers"))
return Animation(channels, extensions, extras, name, samplers)
def to_dict(self):
result = {}
result["channels"] = from_list(lambda x: to_class(AnimationChannel, x), self.channels)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["samplers"] = from_list(lambda x: to_class(AnimationSampler, x), self.samplers)
return result
class Asset:
"""Metadata about the glTF asset."""
def __init__(self, copyright, extensions, extras, generator, min_version, version):
self.copyright = copyright
self.extensions = extensions
self.extras = extras
self.generator = generator
self.min_version = min_version
self.version = version
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
copyright = from_union([from_str, from_none], obj.get("copyright"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
generator = from_union([from_str, from_none], obj.get("generator"))
min_version = from_union([from_str, from_none], obj.get("minVersion"))
version = from_str(obj.get("version"))
return Asset(copyright, extensions, extras, generator, min_version, version)
def to_dict(self):
result = {}
result["copyright"] = from_union([from_str, from_none], self.copyright)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["generator"] = from_union([from_str, from_none], self.generator)
result["minVersion"] = from_union([from_str, from_none], self.min_version)
result["version"] = from_str(self.version)
return result
class BufferView:
"""A view into a buffer generally representing a subset of the buffer."""
def __init__(self, buffer, byte_length, byte_offset, byte_stride, extensions, extras, name, target):
self.buffer = buffer
self.byte_length = byte_length
self.byte_offset = byte_offset
self.byte_stride = byte_stride
self.extensions = extensions
self.extras = extras
self.name = name
self.target = target
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
buffer = from_int(obj.get("buffer"))
byte_length = from_int(obj.get("byteLength"))
byte_offset = from_union([from_int, from_none], obj.get("byteOffset"))
byte_stride = from_union([from_int, from_none], obj.get("byteStride"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
target = from_union([from_int, from_none], obj.get("target"))
return BufferView(buffer, byte_length, byte_offset, byte_stride, extensions, extras, name, target)
def to_dict(self):
result = {}
result["buffer"] = from_int(self.buffer)
result["byteLength"] = from_int(self.byte_length)
result["byteOffset"] = from_union([from_int, from_none], self.byte_offset)
result["byteStride"] = from_union([from_int, from_none], self.byte_stride)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["target"] = from_union([from_int, from_none], self.target)
return result
class Buffer:
"""A buffer points to binary geometry, animation, or skins."""
def __init__(self, byte_length, extensions, extras, name, uri):
self.byte_length = byte_length
self.extensions = extensions
self.extras = extras
self.name = name
self.uri = uri
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
byte_length = from_int(obj.get("byteLength"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
uri = from_union([from_str, from_none], obj.get("uri"))
return Buffer(byte_length, extensions, extras, name, uri)
def to_dict(self):
result = {}
result["byteLength"] = from_int(self.byte_length)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["uri"] = from_union([from_str, from_none], self.uri)
return result
class CameraOrthographic:
"""An orthographic camera containing properties to create an orthographic projection matrix."""
def __init__(self, extensions, extras, xmag, ymag, zfar, znear):
self.extensions = extensions
self.extras = extras
self.xmag = xmag
self.ymag = ymag
self.zfar = zfar
self.znear = znear
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
xmag = from_float(obj.get("xmag"))
ymag = from_float(obj.get("ymag"))
zfar = from_float(obj.get("zfar"))
znear = from_float(obj.get("znear"))
return CameraOrthographic(extensions, extras, xmag, ymag, zfar, znear)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["xmag"] = to_float(self.xmag)
result["ymag"] = to_float(self.ymag)
result["zfar"] = to_float(self.zfar)
result["znear"] = to_float(self.znear)
return result
class CameraPerspective:
"""A perspective camera containing properties to create a perspective projection matrix."""
def __init__(self, aspect_ratio, extensions, extras, yfov, zfar, znear):
self.aspect_ratio = aspect_ratio
self.extensions = extensions
self.extras = extras
self.yfov = yfov
self.zfar = zfar
self.znear = znear
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
aspect_ratio = from_union([from_float, from_none], obj.get("aspectRatio"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
yfov = from_float(obj.get("yfov"))
zfar = from_union([from_float, from_none], obj.get("zfar"))
znear = from_float(obj.get("znear"))
return CameraPerspective(aspect_ratio, extensions, extras, yfov, zfar, znear)
def to_dict(self):
result = {}
result["aspectRatio"] = from_union([to_float, from_none], self.aspect_ratio)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["yfov"] = to_float(self.yfov)
result["zfar"] = from_union([to_float, from_none], self.zfar)
result["znear"] = to_float(self.znear)
return result
class Camera:
"""A camera's projection. A node can reference a camera to apply a transform to place the
camera in the scene.
"""
def __init__(self, extensions, extras, name, orthographic, perspective, type):
self.extensions = extensions
self.extras = extras
self.name = name
self.orthographic = orthographic
self.perspective = perspective
self.type = type
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
orthographic = from_union([CameraOrthographic.from_dict, from_none], obj.get("orthographic"))
perspective = from_union([CameraPerspective.from_dict, from_none], obj.get("perspective"))
type = from_str(obj.get("type"))
return Camera(extensions, extras, name, orthographic, perspective, type)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["orthographic"] = from_union([lambda x: to_class(CameraOrthographic, x), from_none], self.orthographic)
result["perspective"] = from_union([lambda x: to_class(CameraPerspective, x), from_none], self.perspective)
result["type"] = from_str(self.type)
return result
class Image:
"""Image data used to create a texture. Image can be referenced by URI or `bufferView`
index. `mimeType` is required in the latter case.
"""
def __init__(self, buffer_view, extensions, extras, mime_type, name, uri):
self.buffer_view = buffer_view
self.extensions = extensions
self.extras = extras
self.mime_type = mime_type
self.name = name
self.uri = uri
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
buffer_view = from_union([from_int, from_none], obj.get("bufferView"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
mime_type = from_union([from_str, from_none], obj.get("mimeType"))
name = from_union([from_str, from_none], obj.get("name"))
uri = from_union([from_str, from_none], obj.get("uri"))
return Image(buffer_view, extensions, extras, mime_type, name, uri)
def to_dict(self):
result = {}
result["bufferView"] = from_union([from_int, from_none], self.buffer_view)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["mimeType"] = from_union([from_str, from_none], self.mime_type)
result["name"] = from_union([from_str, from_none], self.name)
result["uri"] = from_union([from_str, from_none], self.uri)
return result
class TextureInfo:
"""The emissive map texture.
The base color texture.
The metallic-roughness texture.
Reference to a texture.
"""
def __init__(self, extensions, extras, index, tex_coord):
self.extensions = extensions
self.extras = extras
self.index = index
self.tex_coord = tex_coord
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
index = from_int(obj.get("index"))
tex_coord = from_union([from_int, from_none], obj.get("texCoord"))
return TextureInfo(extensions, extras, index, tex_coord)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["index"] = from_int(self.index)
result["texCoord"] = from_union([from_int, from_none], self.tex_coord)
return result
class MaterialNormalTextureInfoClass:
"""The normal map texture.
Reference to a texture.
"""
def __init__(self, extensions, extras, index, scale, tex_coord):
self.extensions = extensions
self.extras = extras
self.index = index
self.scale = scale
self.tex_coord = tex_coord
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
index = from_int(obj.get("index"))
scale = from_union([from_float, from_none], obj.get("scale"))
tex_coord = from_union([from_int, from_none], obj.get("texCoord"))
return MaterialNormalTextureInfoClass(extensions, extras, index, scale, tex_coord)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["index"] = from_int(self.index)
result["scale"] = from_union([to_float, from_none], self.scale)
result["texCoord"] = from_union([from_int, from_none], self.tex_coord)
return result
class MaterialOcclusionTextureInfoClass:
"""The occlusion map texture.
Reference to a texture.
"""
def __init__(self, extensions, extras, index, strength, tex_coord):
self.extensions = extensions
self.extras = extras
self.index = index
self.strength = strength
self.tex_coord = tex_coord
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
index = from_int(obj.get("index"))
strength = from_union([from_float, from_none], obj.get("strength"))
tex_coord = from_union([from_int, from_none], obj.get("texCoord"))
return MaterialOcclusionTextureInfoClass(extensions, extras, index, strength, tex_coord)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["index"] = from_int(self.index)
result["strength"] = from_union([to_float, from_none], self.strength)
result["texCoord"] = from_union([from_int, from_none], self.tex_coord)
return result
class MaterialPBRMetallicRoughness:
"""A set of parameter values that are used to define the metallic-roughness material model
from Physically-Based Rendering (PBR) methodology. When not specified, all the default
values of `pbrMetallicRoughness` apply.
A set of parameter values that are used to define the metallic-roughness material model
from Physically-Based Rendering (PBR) methodology.
"""
def __init__(self, base_color_factor, base_color_texture, extensions, extras, metallic_factor,
metallic_roughness_texture, roughness_factor):
self.base_color_factor = base_color_factor
self.base_color_texture = base_color_texture
self.extensions = extensions
self.extras = extras
self.metallic_factor = metallic_factor
self.metallic_roughness_texture = metallic_roughness_texture
self.roughness_factor = roughness_factor
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
base_color_factor = from_union([lambda x: from_list(from_float, x), from_none], obj.get("baseColorFactor"))
base_color_texture = from_union([TextureInfo.from_dict, from_none], obj.get("baseColorTexture"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
metallic_factor = from_union([from_float, from_none], obj.get("metallicFactor"))
metallic_roughness_texture = from_union([TextureInfo.from_dict, from_none], obj.get("metallicRoughnessTexture"))
roughness_factor = from_union([from_float, from_none], obj.get("roughnessFactor"))
return MaterialPBRMetallicRoughness(base_color_factor, base_color_texture, extensions, extras, metallic_factor,
metallic_roughness_texture, roughness_factor)
def to_dict(self):
result = {}
result["baseColorFactor"] = from_union([lambda x: from_list(to_float, x), from_none], self.base_color_factor)
result["baseColorTexture"] = from_union([lambda x: to_class(TextureInfo, x), from_none],
self.base_color_texture)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["metallicFactor"] = from_union([to_float, from_none], self.metallic_factor)
result["metallicRoughnessTexture"] = from_union([lambda x: to_class(TextureInfo, x), from_none],
self.metallic_roughness_texture)
result["roughnessFactor"] = from_union([to_float, from_none], self.roughness_factor)
return result
class Material:
"""The material appearance of a primitive."""
def __init__(self, alpha_cutoff, alpha_mode, double_sided, emissive_factor, emissive_texture, extensions, extras,
name, normal_texture, occlusion_texture, pbr_metallic_roughness):
self.alpha_cutoff = alpha_cutoff
self.alpha_mode = alpha_mode
self.double_sided = double_sided
self.emissive_factor = emissive_factor
self.emissive_texture = emissive_texture
self.extensions = extensions
self.extras = extras
self.name = name
self.normal_texture = normal_texture
self.occlusion_texture = occlusion_texture
self.pbr_metallic_roughness = pbr_metallic_roughness
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
alpha_cutoff = from_union([from_float, from_none], obj.get("alphaCutoff"))
alpha_mode = from_union([from_str, from_none], obj.get("alphaMode"))
double_sided = from_union([from_bool, from_none], obj.get("doubleSided"))
emissive_factor = from_union([lambda x: from_list(from_float, x), from_none], obj.get("emissiveFactor"))
emissive_texture = from_union([TextureInfo.from_dict, from_none], obj.get("emissiveTexture"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
normal_texture = from_union([MaterialNormalTextureInfoClass.from_dict, from_none], obj.get("normalTexture"))
occlusion_texture = from_union([MaterialOcclusionTextureInfoClass.from_dict, from_none],
obj.get("occlusionTexture"))
pbr_metallic_roughness = from_union([MaterialPBRMetallicRoughness.from_dict, from_none],
obj.get("pbrMetallicRoughness"))
return Material(alpha_cutoff, alpha_mode, double_sided, emissive_factor, emissive_texture, extensions, extras,
name, normal_texture, occlusion_texture, pbr_metallic_roughness)
def to_dict(self):
result = {}
result["alphaCutoff"] = from_union([to_float, from_none], self.alpha_cutoff)
result["alphaMode"] = from_union([from_str, from_none], self.alpha_mode)
result["doubleSided"] = from_union([from_bool, from_none], self.double_sided)
result["emissiveFactor"] = from_union([lambda x: from_list(to_float, x), from_none], self.emissive_factor)
result["emissiveTexture"] = from_union([lambda x: to_class(TextureInfo, x), from_none], self.emissive_texture)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["normalTexture"] = from_union([lambda x: to_class(MaterialNormalTextureInfoClass, x), from_none],
self.normal_texture)
result["occlusionTexture"] = from_union([lambda x: to_class(MaterialOcclusionTextureInfoClass, x), from_none],
self.occlusion_texture)
result["pbrMetallicRoughness"] = from_union([lambda x: to_class(MaterialPBRMetallicRoughness, x), from_none],
self.pbr_metallic_roughness)
return result
class MeshPrimitive:
"""Geometry to be rendered with the given material."""
def __init__(self, attributes, extensions, extras, indices, material, mode, targets):
self.attributes = attributes
self.extensions = extensions
self.extras = extras
self.indices = indices
self.material = material
self.mode = mode
self.targets = targets
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
attributes = from_dict(from_int, obj.get("attributes"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
indices = from_union([from_int, from_none], obj.get("indices"))
material = from_union([from_int, from_none], obj.get("material"))
mode = from_union([from_int, from_none], obj.get("mode"))
targets = from_union([lambda x: from_list(lambda x: from_dict(from_int, x), x), from_none], obj.get("targets"))
return MeshPrimitive(attributes, extensions, extras, indices, material, mode, targets)
def to_dict(self):
result = {}
result["attributes"] = from_dict(from_int, self.attributes)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["indices"] = from_union([from_int, from_none], self.indices)
result["material"] = from_union([from_int, from_none], self.material)
result["mode"] = from_union([from_int, from_none], self.mode)
result["targets"] = from_union([lambda x: from_list(lambda x: from_dict(from_int, x), x), from_none],
self.targets)
return result
class Mesh:
"""A set of primitives to be rendered. A node can contain one mesh. A node's transform
places the mesh in the scene.
"""
def __init__(self, extensions, extras, name, primitives, weights):
self.extensions = extensions
self.extras = extras
self.name = name
self.primitives = primitives
self.weights = weights
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
primitives = from_list(MeshPrimitive.from_dict, obj.get("primitives"))
weights = from_union([lambda x: from_list(from_float, x), from_none], obj.get("weights"))
return Mesh(extensions, extras, name, primitives, weights)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["primitives"] = from_list(lambda x: to_class(MeshPrimitive, x), self.primitives)
result["weights"] = from_union([lambda x: from_list(to_float, x), from_none], self.weights)
return result
class Node:
"""A node in the node hierarchy. When the node contains `skin`, all `mesh.primitives` must
contain `JOINTS_0` and `WEIGHTS_0` attributes. A node can have either a `matrix` or any
combination of `translation`/`rotation`/`scale` (TRS) properties. TRS properties are
converted to matrices and postmultiplied in the `T * R * S` order to compose the
transformation matrix; first the scale is applied to the vertices, then the rotation, and
then the translation. If none are provided, the transform is the identity. When a node is
targeted for animation (referenced by an animation.channel.target), only TRS properties
may be present; `matrix` will not be present.
"""
def __init__(self, camera, children, extensions, extras, matrix, mesh, name, rotation, scale, skin, translation,
weights):
self.camera = camera
self.children = children
self.extensions = extensions
self.extras = extras
self.matrix = matrix
self.mesh = mesh
self.name = name
self.rotation = rotation
self.scale = scale
self.skin = skin
self.translation = translation
self.weights = weights
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
camera = from_union([from_int, from_none], obj.get("camera"))
children = from_union([lambda x: from_list(from_int, x), from_none], obj.get("children"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
matrix = from_union([lambda x: from_list(from_float, x), from_none], obj.get("matrix"))
mesh = from_union([from_int, from_none], obj.get("mesh"))
name = from_union([from_str, from_none], obj.get("name"))
rotation = from_union([lambda x: from_list(from_float, x), from_none], obj.get("rotation"))
scale = from_union([lambda x: from_list(from_float, x), from_none], obj.get("scale"))
skin = from_union([from_int, from_none], obj.get("skin"))
translation = from_union([lambda x: from_list(from_float, x), from_none], obj.get("translation"))
weights = from_union([lambda x: from_list(from_float, x), from_none], obj.get("weights"))
return Node(camera, children, extensions, extras, matrix, mesh, name, rotation, scale, skin, translation,
weights)
def to_dict(self):
result = {}
result["camera"] = from_union([from_int, from_none], self.camera)
result["children"] = from_union([lambda x: from_list(from_int, x), from_none], self.children)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["matrix"] = from_union([lambda x: from_list(to_float, x), from_none], self.matrix)
result["mesh"] = from_union([from_int, from_none], self.mesh)
result["name"] = from_union([from_str, from_none], self.name)
result["rotation"] = from_union([lambda x: from_list(to_float, x), from_none], self.rotation)
result["scale"] = from_union([lambda x: from_list(to_float, x), from_none], self.scale)
result["skin"] = from_union([from_int, from_none], self.skin)
result["translation"] = from_union([lambda x: from_list(to_float, x), from_none], self.translation)
result["weights"] = from_union([lambda x: from_list(to_float, x), from_none], self.weights)
return result
class Sampler:
"""Texture sampler properties for filtering and wrapping modes."""
def __init__(self, extensions, extras, mag_filter, min_filter, name, wrap_s, wrap_t):
self.extensions = extensions
self.extras = extras
self.mag_filter = mag_filter
self.min_filter = min_filter
self.name = name
self.wrap_s = wrap_s
self.wrap_t = wrap_t
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
mag_filter = from_union([from_int, from_none], obj.get("magFilter"))
min_filter = from_union([from_int, from_none], obj.get("minFilter"))
name = from_union([from_str, from_none], obj.get("name"))
wrap_s = from_union([from_int, from_none], obj.get("wrapS"))
wrap_t = from_union([from_int, from_none], obj.get("wrapT"))
return Sampler(extensions, extras, mag_filter, min_filter, name, wrap_s, wrap_t)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["magFilter"] = from_union([from_int, from_none], self.mag_filter)
result["minFilter"] = from_union([from_int, from_none], self.min_filter)
result["name"] = from_union([from_str, from_none], self.name)
result["wrapS"] = from_union([from_int, from_none], self.wrap_s)
result["wrapT"] = from_union([from_int, from_none], self.wrap_t)
return result
class Scene:
"""The root nodes of a scene."""
def __init__(self, extensions, extras, name, nodes):
self.extensions = extensions
self.extras = extras
self.name = name
self.nodes = nodes
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
nodes = from_union([lambda x: from_list(from_int, x), from_none], obj.get("nodes"))
return Scene(extensions, extras, name, nodes)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["nodes"] = from_union([lambda x: from_list(from_int, x), from_none], self.nodes)
return result
class Skin:
"""Joints and matrices defining a skin."""
def __init__(self, extensions, extras, inverse_bind_matrices, joints, name, skeleton):
self.extensions = extensions
self.extras = extras
self.inverse_bind_matrices = inverse_bind_matrices
self.joints = joints
self.name = name
self.skeleton = skeleton
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
inverse_bind_matrices = from_union([from_int, from_none], obj.get("inverseBindMatrices"))
joints = from_list(from_int, obj.get("joints"))
name = from_union([from_str, from_none], obj.get("name"))
skeleton = from_union([from_int, from_none], obj.get("skeleton"))
return Skin(extensions, extras, inverse_bind_matrices, joints, name, skeleton)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["inverseBindMatrices"] = from_union([from_int, from_none], self.inverse_bind_matrices)
result["joints"] = from_list(from_int, self.joints)
result["name"] = from_union([from_str, from_none], self.name)
result["skeleton"] = from_union([from_int, from_none], self.skeleton)
return result
class Texture:
"""A texture and its sampler."""
def __init__(self, extensions, extras, name, sampler, source):
self.extensions = extensions
self.extras = extras
self.name = name
self.sampler = sampler
self.source = source
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extras = obj.get("extras")
name = from_union([from_str, from_none], obj.get("name"))
sampler = from_union([from_int, from_none], obj.get("sampler"))
source = from_int(obj.get("source"))
return Texture(extensions, extras, name, sampler, source)
def to_dict(self):
result = {}
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extras"] = self.extras
result["name"] = from_union([from_str, from_none], self.name)
result["sampler"] = from_union([from_int, from_none], self.sampler)
result["source"] = from_int(self.source) # most viewers can't handle missing sources
return result
class Gltf:
"""The root object for a glTF asset."""
def __init__(self, accessors, animations, asset, buffers, buffer_views, cameras, extensions, extensions_required,
extensions_used, extras, images, materials, meshes, nodes, samplers, scene, scenes, skins, textures):
self.accessors = accessors
self.animations = animations
self.asset = asset
self.buffers = buffers
self.buffer_views = buffer_views
self.cameras = cameras
self.extensions = extensions
self.extensions_required = extensions_required
self.extensions_used = extensions_used
self.extras = extras
self.images = images
self.materials = materials
self.meshes = meshes
self.nodes = nodes
self.samplers = samplers
self.scene = scene
self.scenes = scenes
self.skins = skins
self.textures = textures
@staticmethod
def from_dict(obj):
assert isinstance(obj, dict)
accessors = from_union([lambda x: from_list(Accessor.from_dict, x), from_none], obj.get("accessors"))
animations = from_union([lambda x: from_list(Animation.from_dict, x), from_none], obj.get("animations"))
asset = Asset.from_dict(obj.get("asset"))
buffers = from_union([lambda x: from_list(Buffer.from_dict, x), from_none], obj.get("buffers"))
buffer_views = from_union([lambda x: from_list(BufferView.from_dict, x), from_none], obj.get("bufferViews"))
cameras = from_union([lambda x: from_list(Camera.from_dict, x), from_none], obj.get("cameras"))
extensions = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
obj.get("extensions"))
extensions_required = from_union([lambda x: from_list(from_str, x), from_none], obj.get("extensionsRequired"))
extensions_used = from_union([lambda x: from_list(from_str, x), from_none], obj.get("extensionsUsed"))
extras = obj.get("extras")
images = from_union([lambda x: from_list(Image.from_dict, x), from_none], obj.get("images"))
materials = from_union([lambda x: from_list(Material.from_dict, x), from_none], obj.get("materials"))
meshes = from_union([lambda x: from_list(Mesh.from_dict, x), from_none], obj.get("meshes"))
nodes = from_union([lambda x: from_list(Node.from_dict, x), from_none], obj.get("nodes"))
samplers = from_union([lambda x: from_list(Sampler.from_dict, x), from_none], obj.get("samplers"))
scene = from_union([from_int, from_none], obj.get("scene"))
scenes = from_union([lambda x: from_list(Scene.from_dict, x), from_none], obj.get("scenes"))
skins = from_union([lambda x: from_list(Skin.from_dict, x), from_none], obj.get("skins"))
textures = from_union([lambda x: from_list(Texture.from_dict, x), from_none], obj.get("textures"))
return Gltf(accessors, animations, asset, buffers, buffer_views, cameras, extensions, extensions_required,
extensions_used, extras, images, materials, meshes, nodes, samplers, scene, scenes, skins, textures)
def to_dict(self):
result = {}
result["accessors"] = from_union([lambda x: from_list(lambda x: to_class(Accessor, x), x), from_none],
self.accessors)
result["animations"] = from_union([lambda x: from_list(lambda x: to_class(Animation, x), x), from_none],
self.animations)
result["asset"] = to_class(Asset, self.asset)
result["buffers"] = from_union([lambda x: from_list(lambda x: to_class(Buffer, x), x), from_none], self.buffers)
result["bufferViews"] = from_union([lambda x: from_list(lambda x: to_class(BufferView, x), x), from_none],
self.buffer_views)
result["cameras"] = from_union([lambda x: from_list(lambda x: to_class(Camera, x), x), from_none], self.cameras)
result["extensions"] = from_union([lambda x: from_dict(lambda x: from_dict(lambda x: x, x), x), from_none],
self.extensions)
result["extensionsRequired"] = from_union([lambda x: from_list(from_str, x), from_none],
self.extensions_required)
result["extensionsUsed"] = from_union([lambda x: from_list(from_str, x), from_none], self.extensions_used)
result["extras"] = self.extras
result["images"] = from_union([lambda x: from_list(lambda x: to_class(Image, x), x), from_none], self.images)
result["materials"] = from_union([lambda x: from_list(lambda x: to_class(Material, x), x), from_none],
self.materials)
result["meshes"] = from_union([lambda x: from_list(lambda x: to_class(Mesh, x), x), from_none], self.meshes)
result["nodes"] = from_union([lambda x: from_list(lambda x: to_class(Node, x), x), from_none], self.nodes)
result["samplers"] = from_union([lambda x: from_list(lambda x: to_class(Sampler, x), x), from_none],
self.samplers)
result["scene"] = from_union([from_int, from_none], self.scene)
result["scenes"] = from_union([lambda x: from_list(lambda x: to_class(Scene, x), x), from_none], self.scenes)
result["skins"] = from_union([lambda x: from_list(lambda x: to_class(Skin, x), x), from_none], self.skins)
result["textures"] = from_union([lambda x: from_list(lambda x: to_class(Texture, x), x), from_none],
self.textures)
return result
def gltf_from_dict(s):
return Gltf.from_dict(s)
def gltf_to_dict(x):
return to_class(Gltf, x)
|