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
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
use kserde::*;

use std::collections::HashMap;

/// The root object for a glTF asset.
#[derive(Debug, Clone)]
pub struct GlTf {
    /// Names of glTF extensions used somewhere in this asset.
    pub extensions_used: Vec<String>,
    /// Names of glTF extensions required to properly load this asset.
    pub extensions_required: Vec<String>,
    /// An array of accessors.
    pub accessors: Vec<Accessor>,
    /// An array of keyframe animations.
    pub animations: Vec<Animation>,
    /// Metadata about the glTF asset.
    pub asset: Asset,
    /// An array of buffers.
    pub buffers: Vec<Buffer>,
    /// An array of bufferViews.
    pub buffer_views: Vec<BufferView>,
    /// An array of cameras.
    pub cameras: Vec<Camera>,
    /// An array of images.
    pub images: Vec<Image>,
    /// An array of materials.
    pub materials: Vec<Material>,
    /// An array of meshes.
    pub meshes: Vec<Mesh>,
    /// An array of nodes.
    pub nodes: Vec<Node>,
    /// An array of samplers.
    pub samplers: Vec<Sampler>,
    /// The index of the default scene.
    pub scene: Option<usize>,
    /// An array of scenes.
    pub scenes: Vec<Scene>,
    /// An array of skins.
    pub skins: Vec<Skin>,
    /// An array of textures.
    pub textures: Vec<Texture>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for GlTf {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if !self.extensions_used.is_empty() {
            object.property("extensionsUsed", &self.extensions_used);
        }
        if !self.extensions_required.is_empty() {
            object.property("extensionsRequired", &self.extensions_required);
        }
        if !self.accessors.is_empty() {
            object.property("accessors", &self.accessors);
        }
        if !self.animations.is_empty() {
            object.property("animations", &self.animations);
        }
        object.property("asset", &self.asset);
        if !self.buffers.is_empty() {
            object.property("buffers", &self.buffers);
        }
        if !self.buffer_views.is_empty() {
            object.property("bufferViews", &self.buffer_views);
        }
        if !self.cameras.is_empty() {
            object.property("cameras", &self.cameras);
        }
        if !self.images.is_empty() {
            object.property("images", &self.images);
        }
        if !self.materials.is_empty() {
            object.property("materials", &self.materials);
        }
        if !self.meshes.is_empty() {
            object.property("meshes", &self.meshes);
        }
        if !self.nodes.is_empty() {
            object.property("nodes", &self.nodes);
        }
        if !self.samplers.is_empty() {
            object.property("samplers", &self.samplers);
        }
        if let Some(v) = self.scene.as_ref() {
            object.property("scene", v);
        }
        if !self.scenes.is_empty() {
            object.property("scenes", &self.scenes);
        }
        if !self.skins.is_empty() {
            object.property("skins", &self.skins);
        }
        if !self.textures.is_empty() {
            object.property("textures", &self.textures);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for GlTf {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut extensions_used = None;
        let mut extensions_required = None;
        let mut accessors = None;
        let mut animations = None;
        let mut asset = None;
        let mut buffers = None;
        let mut buffer_views = None;
        let mut cameras = None;
        let mut images = None;
        let mut materials = None;
        let mut meshes = None;
        let mut nodes = None;
        let mut samplers = None;
        let mut scene = None;
        let mut scenes = None;
        let mut skins = None;
        let mut textures = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "extensionsUsed" => extensions_used = <Vec<String>>::deserialize(deserializer),
                "extensionsRequired" => {
                    extensions_required = <Vec<String>>::deserialize(deserializer)
                }
                "accessors" => accessors = <Vec<Accessor>>::deserialize(deserializer),
                "animations" => animations = <Vec<Animation>>::deserialize(deserializer),
                "asset" => asset = <Asset>::deserialize(deserializer),
                "buffers" => buffers = <Vec<Buffer>>::deserialize(deserializer),
                "bufferViews" => buffer_views = <Vec<BufferView>>::deserialize(deserializer),
                "cameras" => cameras = <Vec<Camera>>::deserialize(deserializer),
                "images" => images = <Vec<Image>>::deserialize(deserializer),
                "materials" => materials = <Vec<Material>>::deserialize(deserializer),
                "meshes" => meshes = <Vec<Mesh>>::deserialize(deserializer),
                "nodes" => nodes = <Vec<Node>>::deserialize(deserializer),
                "samplers" => samplers = <Vec<Sampler>>::deserialize(deserializer),
                "scene" => scene = <usize>::deserialize(deserializer),
                "scenes" => scenes = <Vec<Scene>>::deserialize(deserializer),
                "skins" => skins = <Vec<Skin>>::deserialize(deserializer),
                "textures" => textures = <Vec<Texture>>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            extensions_used: extensions_used.unwrap_or_else(|| Vec::new()),
            extensions_required: extensions_required.unwrap_or_else(|| Vec::new()),
            accessors: accessors.unwrap_or_else(|| Vec::new()),
            animations: animations.unwrap_or_else(|| Vec::new()),
            asset: asset?,
            buffers: buffers.unwrap_or_else(|| Vec::new()),
            buffer_views: buffer_views.unwrap_or_else(|| Vec::new()),
            cameras: cameras.unwrap_or_else(|| Vec::new()),
            images: images.unwrap_or_else(|| Vec::new()),
            materials: materials.unwrap_or_else(|| Vec::new()),
            meshes: meshes.unwrap_or_else(|| Vec::new()),
            nodes: nodes.unwrap_or_else(|| Vec::new()),
            samplers: samplers.unwrap_or_else(|| Vec::new()),
            scene: scene,
            scenes: scenes.unwrap_or_else(|| Vec::new()),
            skins: skins.unwrap_or_else(|| Vec::new()),
            textures: textures.unwrap_or_else(|| Vec::new()),
            extensions: extensions,
        })
    }
}

/// A texture and its sampler.
#[derive(Debug, Clone)]
pub struct Texture {
    /// The index of the sampler used by this texture. When undefined, a sampler with repeat wrapping and auto filtering should be used.
    pub sampler: Option<usize>,
    /// The index of the image used by this texture. When undefined, it is expected that an extension or other mechanism will supply an alternate texture source, otherwise behavior is undefined.
    pub source: Option<usize>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Texture {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.sampler.as_ref() {
            object.property("sampler", v);
        }
        if let Some(v) = self.source.as_ref() {
            object.property("source", v);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Texture {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut sampler = None;
        let mut source = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "sampler" => sampler = <usize>::deserialize(deserializer),
                "source" => source = <usize>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            sampler: sampler,
            source: source,
            name: name,
            extensions: extensions,
        })
    }
}

/// Joints and matrices defining a skin.
#[derive(Debug, Clone)]
pub struct Skin {
    /// The index of the accessor containing the floating-point 4x4 inverse-bind matrices.  The default is that each matrix is a 4x4 identity matrix, which implies that inverse-bind matrices were pre-applied.
    pub inverse_bind_matrices: Option<usize>,
    /// The index of the node used as a skeleton root.
    pub skeleton: Option<usize>,
    /// Indices of skeleton nodes, used as joints in this skin.
    pub joints: Vec<usize>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Skin {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.inverse_bind_matrices.as_ref() {
            object.property("inverseBindMatrices", v);
        }
        if let Some(v) = self.skeleton.as_ref() {
            object.property("skeleton", v);
        }
        object.property("joints", &self.joints);
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Skin {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut inverse_bind_matrices = None;
        let mut skeleton = None;
        let mut joints = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "inverseBindMatrices" => inverse_bind_matrices = <usize>::deserialize(deserializer),
                "skeleton" => skeleton = <usize>::deserialize(deserializer),
                "joints" => joints = <Vec<usize>>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            inverse_bind_matrices: inverse_bind_matrices,
            skeleton: skeleton,
            joints: joints?,
            name: name,
            extensions: extensions,
        })
    }
}

/// The root nodes of a scene.
#[derive(Debug, Clone)]
pub struct Scene {
    /// The indices of each root node.
    pub nodes: Vec<usize>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Scene {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if !self.nodes.is_empty() {
            object.property("nodes", &self.nodes);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Scene {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut nodes = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "nodes" => nodes = <Vec<usize>>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            nodes: nodes.unwrap_or_else(|| Vec::new()),
            name: name,
            extensions: extensions,
        })
    }
}

/// Texture sampler properties for filtering and wrapping modes.
#[derive(Debug, Clone)]
pub struct Sampler {
    /// Magnification filter.
    pub mag_filter: Option<SamplerMagFilter>,
    /// Minification filter.
    pub min_filter: Option<SamplerMinFilter>,
    /// s wrapping mode.
    pub wrap_s: Option<SamplerWrapS>,
    /// t wrapping mode.
    pub wrap_t: Option<SamplerWrapT>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Sampler {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.mag_filter.as_ref() {
            object.property("magFilter", v);
        }
        if let Some(v) = self.min_filter.as_ref() {
            object.property("minFilter", v);
        }
        if let Some(v) = self.wrap_s.as_ref() {
            object.property("wrapS", v);
        }
        if let Some(v) = self.wrap_t.as_ref() {
            object.property("wrapT", v);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Sampler {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut mag_filter = None;
        let mut min_filter = None;
        let mut wrap_s = None;
        let mut wrap_t = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "magFilter" => mag_filter = <SamplerMagFilter>::deserialize(deserializer),
                "minFilter" => min_filter = <SamplerMinFilter>::deserialize(deserializer),
                "wrapS" => wrap_s = <SamplerWrapS>::deserialize(deserializer),
                "wrapT" => wrap_t = <SamplerWrapT>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            mag_filter: mag_filter,
            min_filter: min_filter,
            wrap_s: wrap_s,
            wrap_t: wrap_t,
            name: name,
            extensions: extensions,
        })
    }
}

/// t wrapping mode.
#[derive(Debug, Clone)]
pub enum SamplerWrapT {
    ClampToEdge,
    MirroredRepeat,
    Repeat,
}

impl Serialize for SamplerWrapT {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::ClampToEdge => 33071.serialize(serializer),
            Self::MirroredRepeat => 33648.serialize(serializer),
            Self::Repeat => 10497.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for SamplerWrapT {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            33071 => Self::ClampToEdge,
            33648 => Self::MirroredRepeat,
            10497 => Self::Repeat,
            _ => None?,
        })
    }
}

/// s wrapping mode.
#[derive(Debug, Clone)]
pub enum SamplerWrapS {
    ClampToEdge,
    MirroredRepeat,
    Repeat,
}

impl Serialize for SamplerWrapS {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::ClampToEdge => 33071.serialize(serializer),
            Self::MirroredRepeat => 33648.serialize(serializer),
            Self::Repeat => 10497.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for SamplerWrapS {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            33071 => Self::ClampToEdge,
            33648 => Self::MirroredRepeat,
            10497 => Self::Repeat,
            _ => None?,
        })
    }
}

/// Minification filter.
#[derive(Debug, Clone)]
pub enum SamplerMinFilter {
    Nearest,
    Linear,
    NearestMipmapNearest,
    LinearMipmapNearest,
    NearestMipmapLinear,
    LinearMipmapLinear,
}

impl Serialize for SamplerMinFilter {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Nearest => 9728.serialize(serializer),
            Self::Linear => 9729.serialize(serializer),
            Self::NearestMipmapNearest => 9984.serialize(serializer),
            Self::LinearMipmapNearest => 9985.serialize(serializer),
            Self::NearestMipmapLinear => 9986.serialize(serializer),
            Self::LinearMipmapLinear => 9987.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for SamplerMinFilter {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            9728 => Self::Nearest,
            9729 => Self::Linear,
            9984 => Self::NearestMipmapNearest,
            9985 => Self::LinearMipmapNearest,
            9986 => Self::NearestMipmapLinear,
            9987 => Self::LinearMipmapLinear,
            _ => None?,
        })
    }
}

/// Magnification filter.
#[derive(Debug, Clone)]
pub enum SamplerMagFilter {
    Nearest,
    Linear,
}

impl Serialize for SamplerMagFilter {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Nearest => 9728.serialize(serializer),
            Self::Linear => 9729.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for SamplerMagFilter {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            9728 => Self::Nearest,
            9729 => Self::Linear,
            _ => None?,
        })
    }
}

/// 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.
#[derive(Debug, Clone)]
pub struct Node {
    /// The index of the camera referenced by this node.
    pub camera: Option<usize>,
    /// The indices of this node's children.
    pub children: Vec<usize>,
    /// The index of the skin referenced by this node.
    pub skin: Option<usize>,
    /// A floating-point 4x4 transformation matrix stored in column-major order.
    pub matrix: Option<[f32; 16]>,
    /// The index of the mesh in this node.
    pub mesh: Option<usize>,
    /// The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar.
    pub rotation: Option<[f32; 4]>,
    /// The node's non-uniform scale, given as the scaling factors along the x, y, and z axes.
    pub scale: Option<[f32; 3]>,
    /// The node's translation along the x, y, and z axes.
    pub translation: Option<[f32; 3]>,
    /// The weights of the instantiated Morph Target. Number of elements must match number of Morph Targets of used mesh.
    pub weights: Vec<f32>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Node {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.camera.as_ref() {
            object.property("camera", v);
        }
        if !self.children.is_empty() {
            object.property("children", &self.children);
        }
        if let Some(v) = self.skin.as_ref() {
            object.property("skin", v);
        }
        if let Some(v) = self.matrix.as_ref() {
            object.property("matrix", v);
        }
        if let Some(v) = self.mesh.as_ref() {
            object.property("mesh", v);
        }
        if let Some(v) = self.rotation.as_ref() {
            object.property("rotation", v);
        }
        if let Some(v) = self.scale.as_ref() {
            object.property("scale", v);
        }
        if let Some(v) = self.translation.as_ref() {
            object.property("translation", v);
        }
        if !self.weights.is_empty() {
            object.property("weights", &self.weights);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Node {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut camera = None;
        let mut children = None;
        let mut skin = None;
        let mut matrix = None;
        let mut mesh = None;
        let mut rotation = None;
        let mut scale = None;
        let mut translation = None;
        let mut weights = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "camera" => camera = <usize>::deserialize(deserializer),
                "children" => children = <Vec<usize>>::deserialize(deserializer),
                "skin" => skin = <usize>::deserialize(deserializer),
                "matrix" => matrix = <[f32; 16]>::deserialize(deserializer),
                "mesh" => mesh = <usize>::deserialize(deserializer),
                "rotation" => rotation = <[f32; 4]>::deserialize(deserializer),
                "scale" => scale = <[f32; 3]>::deserialize(deserializer),
                "translation" => translation = <[f32; 3]>::deserialize(deserializer),
                "weights" => weights = <Vec<f32>>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            camera: camera,
            children: children.unwrap_or_else(|| Vec::new()),
            skin: skin,
            matrix: matrix,
            mesh: mesh,
            rotation: rotation,
            scale: scale,
            translation: translation,
            weights: weights.unwrap_or_else(|| Vec::new()),
            name: name,
            extensions: extensions,
        })
    }
}

/// A set of primitives to be rendered.  A node can contain one mesh.  A node's transform places the mesh in the scene.
#[derive(Debug, Clone)]
pub struct Mesh {
    /// An array of primitives, each defining geometry to be rendered with a material.
    pub primitives: Vec<MeshPrimitive>,
    /// Array of weights to be applied to the Morph Targets.
    pub weights: Vec<f32>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Mesh {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("primitives", &self.primitives);
        if !self.weights.is_empty() {
            object.property("weights", &self.weights);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Mesh {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut primitives = None;
        let mut weights = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "primitives" => primitives = <Vec<MeshPrimitive>>::deserialize(deserializer),
                "weights" => weights = <Vec<f32>>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            primitives: primitives?,
            weights: weights.unwrap_or_else(|| Vec::new()),
            name: name,
            extensions: extensions,
        })
    }
}

/// Geometry to be rendered with the given material.
#[derive(Debug, Clone)]
pub struct MeshPrimitive {
    /// A dictionary object, where each key corresponds to mesh attribute semantic and each value is the index of the accessor containing attribute's data.
    pub attributes: HashMap<String, usize>,
    /// The index of the accessor that contains the indices.
    pub indices: Option<usize>,
    /// The index of the material to apply to this primitive when rendering.
    pub material: Option<usize>,
    /// The type of primitives to render.
    pub mode: Option<MeshPrimitiveMode>,
    /// An array of Morph Targets, each  Morph Target is a dictionary mapping attributes (only `POSITION`, `NORMAL`, and `TANGENT` supported) to their deviations in the Morph Target.
    pub targets: Vec<HashMap<String, usize>>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for MeshPrimitive {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("attributes", &self.attributes);
        if let Some(v) = self.indices.as_ref() {
            object.property("indices", v);
        }
        if let Some(v) = self.material.as_ref() {
            object.property("material", v);
        }
        if let Some(v) = self.mode.as_ref() {
            object.property("mode", v);
        }
        if !self.targets.is_empty() {
            object.property("targets", &self.targets);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for MeshPrimitive {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut attributes = None;
        let mut indices = None;
        let mut material = None;
        let mut mode = None;
        let mut targets = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "attributes" => attributes = <HashMap<String, usize>>::deserialize(deserializer),
                "indices" => indices = <usize>::deserialize(deserializer),
                "material" => material = <usize>::deserialize(deserializer),
                "mode" => mode = <MeshPrimitiveMode>::deserialize(deserializer),
                "targets" => targets = <Vec<HashMap<String, usize>>>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            attributes: attributes?,
            indices: indices,
            material: material,
            mode: mode,
            targets: targets.unwrap_or_else(|| Vec::new()),
            extensions: extensions,
        })
    }
}

/// The type of primitives to render.
#[derive(Debug, Clone)]
pub enum MeshPrimitiveMode {
    Points,
    Lines,
    LineLoop,
    LineStrip,
    Triangles,
    TriangleStrip,
    TriangleFan,
}

impl Serialize for MeshPrimitiveMode {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Points => 0.serialize(serializer),
            Self::Lines => 1.serialize(serializer),
            Self::LineLoop => 2.serialize(serializer),
            Self::LineStrip => 3.serialize(serializer),
            Self::Triangles => 4.serialize(serializer),
            Self::TriangleStrip => 5.serialize(serializer),
            Self::TriangleFan => 6.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for MeshPrimitiveMode {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            0 => Self::Points,
            1 => Self::Lines,
            2 => Self::LineLoop,
            3 => Self::LineStrip,
            4 => Self::Triangles,
            5 => Self::TriangleStrip,
            6 => Self::TriangleFan,
            _ => None?,
        })
    }
}

/// The material appearance of a primitive.
#[derive(Debug, Clone)]
pub struct Material {
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
    /// 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.
    pub pbr_metallic_roughness: Option<MaterialPbrMetallicRoughness>,
    /// The normal map texture.
    pub normal_texture: Option<MaterialNormalTextureInfo>,
    /// The occlusion map texture.
    pub occlusion_texture: Option<MaterialOcclusionTextureInfo>,
    /// The emissive map texture.
    pub emissive_texture: Option<TextureInfo>,
    /// The emissive color of the material.
    pub emissive_factor: Option<[f32; 3]>,
    /// The alpha rendering mode of the material.
    pub alpha_mode: Option<MaterialAlphaMode>,
    /// The alpha cutoff value of the material.
    pub alpha_cutoff: Option<f32>,
    /// Specifies whether the material is double sided.
    pub double_sided: Option<bool>,
}

impl Serialize for Material {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        if let Some(v) = self.pbr_metallic_roughness.as_ref() {
            object.property("pbrMetallicRoughness", v);
        }
        if let Some(v) = self.normal_texture.as_ref() {
            object.property("normalTexture", v);
        }
        if let Some(v) = self.occlusion_texture.as_ref() {
            object.property("occlusionTexture", v);
        }
        if let Some(v) = self.emissive_texture.as_ref() {
            object.property("emissiveTexture", v);
        }
        if let Some(v) = self.emissive_factor.as_ref() {
            object.property("emissiveFactor", v);
        }
        if let Some(v) = self.alpha_mode.as_ref() {
            object.property("alphaMode", v);
        }
        if let Some(v) = self.alpha_cutoff.as_ref() {
            object.property("alphaCutoff", v);
        }
        if let Some(v) = self.double_sided.as_ref() {
            object.property("doubleSided", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Material {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut name = None;
        let mut extensions = None;
        let mut pbr_metallic_roughness = None;
        let mut normal_texture = None;
        let mut occlusion_texture = None;
        let mut emissive_texture = None;
        let mut emissive_factor = None;
        let mut alpha_mode = None;
        let mut alpha_cutoff = None;
        let mut double_sided = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                "pbrMetallicRoughness" => {
                    pbr_metallic_roughness =
                        <MaterialPbrMetallicRoughness>::deserialize(deserializer)
                }
                "normalTexture" => {
                    normal_texture = <MaterialNormalTextureInfo>::deserialize(deserializer)
                }
                "occlusionTexture" => {
                    occlusion_texture = <MaterialOcclusionTextureInfo>::deserialize(deserializer)
                }
                "emissiveTexture" => emissive_texture = <TextureInfo>::deserialize(deserializer),
                "emissiveFactor" => emissive_factor = <[f32; 3]>::deserialize(deserializer),
                "alphaMode" => alpha_mode = <MaterialAlphaMode>::deserialize(deserializer),
                "alphaCutoff" => alpha_cutoff = <f32>::deserialize(deserializer),
                "doubleSided" => double_sided = <bool>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            name: name,
            extensions: extensions,
            pbr_metallic_roughness: pbr_metallic_roughness,
            normal_texture: normal_texture,
            occlusion_texture: occlusion_texture,
            emissive_texture: emissive_texture,
            emissive_factor: emissive_factor,
            alpha_mode: alpha_mode,
            alpha_cutoff: alpha_cutoff,
            double_sided: double_sided,
        })
    }
}

/// The alpha rendering mode of the material.
#[derive(Debug, Clone)]
pub enum MaterialAlphaMode {
    /// The alpha value is ignored and the rendered output is fully opaque.
    Opaque,
    /// The rendered output is either fully opaque or fully transparent depending on the alpha value and the specified alpha cutoff value.
    Mask,
    /// The alpha value is used to composite the source and destination areas. The rendered output is combined with the background using the normal painting operation (i.e. the Porter and Duff over operator).
    Blend,
}

impl Serialize for MaterialAlphaMode {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Opaque => "OPAQUE".serialize(serializer),
            Self::Mask => "MASK".serialize(serializer),
            Self::Blend => "BLEND".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for MaterialAlphaMode {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "OPAQUE" => Self::Opaque,
            "MASK" => Self::Mask,
            "BLEND" => Self::Blend,
            _ => None?,
        })
    }
}

/// The occlusion map texture.
#[derive(Debug, Clone)]
pub struct MaterialOcclusionTextureInfo {
    /// The index of the texture.
    pub index: usize,
    /// The set index of texture's TEXCOORD attribute used for texture coordinate mapping.
    pub tex_coord: Option<usize>,
    /// A scalar multiplier controlling the amount of occlusion applied.
    pub strength: Option<f32>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for MaterialOcclusionTextureInfo {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("index", &self.index);
        if let Some(v) = self.tex_coord.as_ref() {
            object.property("texCoord", v);
        }
        if let Some(v) = self.strength.as_ref() {
            object.property("strength", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for MaterialOcclusionTextureInfo {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut index = None;
        let mut tex_coord = None;
        let mut strength = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "index" => index = <usize>::deserialize(deserializer),
                "texCoord" => tex_coord = <usize>::deserialize(deserializer),
                "strength" => strength = <f32>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            index: index?,
            tex_coord: tex_coord,
            strength: strength,
            extensions: extensions,
        })
    }
}

/// The normal map texture.
#[derive(Debug, Clone)]
pub struct MaterialNormalTextureInfo {
    /// The index of the texture.
    pub index: usize,
    /// The set index of texture's TEXCOORD attribute used for texture coordinate mapping.
    pub tex_coord: Option<usize>,
    /// The scalar multiplier applied to each normal vector of the normal texture.
    pub scale: Option<f32>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for MaterialNormalTextureInfo {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("index", &self.index);
        if let Some(v) = self.tex_coord.as_ref() {
            object.property("texCoord", v);
        }
        if let Some(v) = self.scale.as_ref() {
            object.property("scale", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for MaterialNormalTextureInfo {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut index = None;
        let mut tex_coord = None;
        let mut scale = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "index" => index = <usize>::deserialize(deserializer),
                "texCoord" => tex_coord = <usize>::deserialize(deserializer),
                "scale" => scale = <f32>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            index: index?,
            tex_coord: tex_coord,
            scale: scale,
            extensions: extensions,
        })
    }
}

/// 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.
#[derive(Debug, Clone)]
pub struct MaterialPbrMetallicRoughness {
    /// The material's base color factor.
    pub base_color_factor: Option<[f32; 4]>,
    /// The base color texture.
    pub base_color_texture: Option<TextureInfo>,
    /// The metalness of the material.
    pub metallic_factor: Option<f32>,
    /// The roughness of the material.
    pub roughness_factor: Option<f32>,
    /// The metallic-roughness texture.
    pub metallic_roughness_texture: Option<TextureInfo>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for MaterialPbrMetallicRoughness {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.base_color_factor.as_ref() {
            object.property("baseColorFactor", v);
        }
        if let Some(v) = self.base_color_texture.as_ref() {
            object.property("baseColorTexture", v);
        }
        if let Some(v) = self.metallic_factor.as_ref() {
            object.property("metallicFactor", v);
        }
        if let Some(v) = self.roughness_factor.as_ref() {
            object.property("roughnessFactor", v);
        }
        if let Some(v) = self.metallic_roughness_texture.as_ref() {
            object.property("metallicRoughnessTexture", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for MaterialPbrMetallicRoughness {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut base_color_factor = None;
        let mut base_color_texture = None;
        let mut metallic_factor = None;
        let mut roughness_factor = None;
        let mut metallic_roughness_texture = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "baseColorFactor" => base_color_factor = <[f32; 4]>::deserialize(deserializer),
                "baseColorTexture" => base_color_texture = <TextureInfo>::deserialize(deserializer),
                "metallicFactor" => metallic_factor = <f32>::deserialize(deserializer),
                "roughnessFactor" => roughness_factor = <f32>::deserialize(deserializer),
                "metallicRoughnessTexture" => {
                    metallic_roughness_texture = <TextureInfo>::deserialize(deserializer)
                }
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            base_color_factor: base_color_factor,
            base_color_texture: base_color_texture,
            metallic_factor: metallic_factor,
            roughness_factor: roughness_factor,
            metallic_roughness_texture: metallic_roughness_texture,
            extensions: extensions,
        })
    }
}

/// The base color texture.
#[derive(Debug, Clone)]
pub struct TextureInfo {
    /// The index of the texture.
    pub index: usize,
    /// The set index of texture's TEXCOORD attribute used for texture coordinate mapping.
    pub tex_coord: Option<usize>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for TextureInfo {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("index", &self.index);
        if let Some(v) = self.tex_coord.as_ref() {
            object.property("texCoord", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for TextureInfo {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut index = None;
        let mut tex_coord = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "index" => index = <usize>::deserialize(deserializer),
                "texCoord" => tex_coord = <usize>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            index: index?,
            tex_coord: tex_coord,
            extensions: extensions,
        })
    }
}

/// Image data used to create a texture. Image can be referenced by URI or `bufferView` index. `mimeType` is required in the latter case.
#[derive(Debug, Clone)]
pub struct Image {
    /// The uri of the image.
    pub uri: Option<String>,
    /// The image's MIME type. Required if `bufferView` is defined.
    pub mime_type: Option<ImageMimeType>,
    /// The index of the bufferView that contains the image. Use this instead of the image's uri property.
    pub buffer_view: Option<usize>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Image {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.uri.as_ref() {
            object.property("uri", v);
        }
        if let Some(v) = self.mime_type.as_ref() {
            object.property("mimeType", v);
        }
        if let Some(v) = self.buffer_view.as_ref() {
            object.property("bufferView", v);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Image {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut uri = None;
        let mut mime_type = None;
        let mut buffer_view = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "uri" => uri = <String>::deserialize(deserializer),
                "mimeType" => mime_type = <ImageMimeType>::deserialize(deserializer),
                "bufferView" => buffer_view = <usize>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            uri: uri,
            mime_type: mime_type,
            buffer_view: buffer_view,
            name: name,
            extensions: extensions,
        })
    }
}

/// The image's MIME type. Required if `bufferView` is defined.
#[derive(Debug, Clone)]
pub enum ImageMimeType {
    ImageJpeg,
    ImagePng,
}

impl Serialize for ImageMimeType {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::ImageJpeg => "image/jpeg".serialize(serializer),
            Self::ImagePng => "image/png".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for ImageMimeType {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "image/jpeg" => Self::ImageJpeg,
            "image/png" => Self::ImagePng,
            _ => None?,
        })
    }
}

/// A camera's projection.  A node can reference a camera to apply a transform to place the camera in the scene.
#[derive(Debug, Clone)]
pub struct Camera {
    /// An orthographic camera containing properties to create an orthographic projection matrix.
    pub orthographic: Option<CameraOrthographic>,
    /// A perspective camera containing properties to create a perspective projection matrix.
    pub perspective: Option<CameraPerspective>,
    /// Specifies if the camera uses a perspective or orthographic projection.
    pub type_: CameraType,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Camera {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.orthographic.as_ref() {
            object.property("orthographic", v);
        }
        if let Some(v) = self.perspective.as_ref() {
            object.property("perspective", v);
        }
        object.property("type", &self.type_);
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Camera {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut orthographic = None;
        let mut perspective = None;
        let mut type_ = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "orthographic" => orthographic = <CameraOrthographic>::deserialize(deserializer),
                "perspective" => perspective = <CameraPerspective>::deserialize(deserializer),
                "type" => type_ = <CameraType>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            orthographic: orthographic,
            perspective: perspective,
            type_: type_?,
            name: name,
            extensions: extensions,
        })
    }
}

/// Specifies if the camera uses a perspective or orthographic projection.
#[derive(Debug, Clone)]
pub enum CameraType {
    Perspective,
    Orthographic,
}

impl Serialize for CameraType {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Perspective => "perspective".serialize(serializer),
            Self::Orthographic => "orthographic".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for CameraType {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "perspective" => Self::Perspective,
            "orthographic" => Self::Orthographic,
            _ => None?,
        })
    }
}

/// A perspective camera containing properties to create a perspective projection matrix.
#[derive(Debug, Clone)]
pub struct CameraPerspective {
    /// The floating-point aspect ratio of the field of view.
    pub aspect_ratio: Option<f32>,
    /// The floating-point vertical field of view in radians.
    pub yfov: f32,
    /// The floating-point distance to the far clipping plane.
    pub zfar: Option<f32>,
    /// The floating-point distance to the near clipping plane.
    pub znear: f32,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for CameraPerspective {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.aspect_ratio.as_ref() {
            object.property("aspectRatio", v);
        }
        object.property("yfov", &self.yfov);
        if let Some(v) = self.zfar.as_ref() {
            object.property("zfar", v);
        }
        object.property("znear", &self.znear);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for CameraPerspective {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut aspect_ratio = None;
        let mut yfov = None;
        let mut zfar = None;
        let mut znear = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "aspectRatio" => aspect_ratio = <f32>::deserialize(deserializer),
                "yfov" => yfov = <f32>::deserialize(deserializer),
                "zfar" => zfar = <f32>::deserialize(deserializer),
                "znear" => znear = <f32>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            aspect_ratio: aspect_ratio,
            yfov: yfov?,
            zfar: zfar,
            znear: znear?,
            extensions: extensions,
        })
    }
}

/// An orthographic camera containing properties to create an orthographic projection matrix.
#[derive(Debug, Clone)]
pub struct CameraOrthographic {
    /// The floating-point horizontal magnification of the view. Must not be zero.
    pub xmag: f32,
    /// The floating-point vertical magnification of the view. Must not be zero.
    pub ymag: f32,
    /// The floating-point distance to the far clipping plane. `zfar` must be greater than `znear`.
    pub zfar: f32,
    /// The floating-point distance to the near clipping plane.
    pub znear: f32,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for CameraOrthographic {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("xmag", &self.xmag);
        object.property("ymag", &self.ymag);
        object.property("zfar", &self.zfar);
        object.property("znear", &self.znear);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for CameraOrthographic {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut xmag = None;
        let mut ymag = None;
        let mut zfar = None;
        let mut znear = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "xmag" => xmag = <f32>::deserialize(deserializer),
                "ymag" => ymag = <f32>::deserialize(deserializer),
                "zfar" => zfar = <f32>::deserialize(deserializer),
                "znear" => znear = <f32>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            xmag: xmag?,
            ymag: ymag?,
            zfar: zfar?,
            znear: znear?,
            extensions: extensions,
        })
    }
}

/// A view into a buffer generally representing a subset of the buffer.
#[derive(Debug, Clone)]
pub struct BufferView {
    /// The index of the buffer.
    pub buffer: usize,
    /// The offset into the buffer in bytes.
    pub byte_offset: Option<usize>,
    /// The length of the bufferView in bytes.
    pub byte_length: usize,
    /// The stride, in bytes.
    pub byte_stride: Option<usize>,
    /// The target that the GPU buffer should be bound to.
    pub target: Option<BufferViewTarget>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for BufferView {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("buffer", &self.buffer);
        if let Some(v) = self.byte_offset.as_ref() {
            object.property("byteOffset", v);
        }
        object.property("byteLength", &self.byte_length);
        if let Some(v) = self.byte_stride.as_ref() {
            object.property("byteStride", v);
        }
        if let Some(v) = self.target.as_ref() {
            object.property("target", v);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for BufferView {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut buffer = None;
        let mut byte_offset = None;
        let mut byte_length = None;
        let mut byte_stride = None;
        let mut target = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "buffer" => buffer = <usize>::deserialize(deserializer),
                "byteOffset" => byte_offset = <usize>::deserialize(deserializer),
                "byteLength" => byte_length = <usize>::deserialize(deserializer),
                "byteStride" => byte_stride = <usize>::deserialize(deserializer),
                "target" => target = <BufferViewTarget>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            buffer: buffer?,
            byte_offset: byte_offset,
            byte_length: byte_length?,
            byte_stride: byte_stride,
            target: target,
            name: name,
            extensions: extensions,
        })
    }
}

/// The target that the GPU buffer should be bound to.
#[derive(Debug, Clone)]
pub enum BufferViewTarget {
    ArrayBuffer,
    ElementArrayBuffer,
}

impl Serialize for BufferViewTarget {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::ArrayBuffer => 34962.serialize(serializer),
            Self::ElementArrayBuffer => 34963.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for BufferViewTarget {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            34962 => Self::ArrayBuffer,
            34963 => Self::ElementArrayBuffer,
            _ => None?,
        })
    }
}

/// A buffer points to binary geometry, animation, or skins.
#[derive(Debug, Clone)]
pub struct Buffer {
    /// The uri of the buffer.
    pub uri: Option<String>,
    /// The length of the buffer in bytes.
    pub byte_length: usize,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Buffer {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.uri.as_ref() {
            object.property("uri", v);
        }
        object.property("byteLength", &self.byte_length);
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Buffer {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut uri = None;
        let mut byte_length = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "uri" => uri = <String>::deserialize(deserializer),
                "byteLength" => byte_length = <usize>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            uri: uri,
            byte_length: byte_length?,
            name: name,
            extensions: extensions,
        })
    }
}

/// Metadata about the glTF asset.
#[derive(Debug, Clone)]
pub struct Asset {
    /// A copyright message suitable for display to credit the content creator.
    pub copyright: Option<String>,
    /// Tool that generated this glTF model.  Useful for debugging.
    pub generator: Option<String>,
    /// The glTF version that this asset targets.
    pub version: String,
    /// The minimum glTF version that this asset targets.
    pub min_version: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Asset {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.copyright.as_ref() {
            object.property("copyright", v);
        }
        if let Some(v) = self.generator.as_ref() {
            object.property("generator", v);
        }
        object.property("version", &self.version);
        if let Some(v) = self.min_version.as_ref() {
            object.property("minVersion", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Asset {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut copyright = None;
        let mut generator = None;
        let mut version = None;
        let mut min_version = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "copyright" => copyright = <String>::deserialize(deserializer),
                "generator" => generator = <String>::deserialize(deserializer),
                "version" => version = <String>::deserialize(deserializer),
                "minVersion" => min_version = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            copyright: copyright,
            generator: generator,
            version: version?,
            min_version: min_version,
            extensions: extensions,
        })
    }
}

/// A keyframe animation.
#[derive(Debug, Clone)]
pub struct Animation {
    /// An array of channels, each of which targets an animation's sampler at a node's property. Different channels of the same animation can't have equal targets.
    pub channels: Vec<AnimationChannel>,
    /// An array of samplers that combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target).
    pub samplers: Vec<AnimationSampler>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Animation {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("channels", &self.channels);
        object.property("samplers", &self.samplers);
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Animation {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut channels = None;
        let mut samplers = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "channels" => channels = <Vec<AnimationChannel>>::deserialize(deserializer),
                "samplers" => samplers = <Vec<AnimationSampler>>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            channels: channels?,
            samplers: samplers?,
            name: name,
            extensions: extensions,
        })
    }
}

/// Combines input and output accessors with an interpolation algorithm to define a keyframe graph (but not its target).
#[derive(Debug, Clone)]
pub struct AnimationSampler {
    /// The index of an accessor containing keyframe input values, e.g., time.
    pub input: usize,
    /// Interpolation algorithm.
    pub interpolation: Option<AnimationSamplerInterpolation>,
    /// The index of an accessor, containing keyframe output values.
    pub output: usize,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AnimationSampler {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("input", &self.input);
        if let Some(v) = self.interpolation.as_ref() {
            object.property("interpolation", v);
        }
        object.property("output", &self.output);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AnimationSampler {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut input = None;
        let mut interpolation = None;
        let mut output = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "input" => input = <usize>::deserialize(deserializer),
                "interpolation" => {
                    interpolation = <AnimationSamplerInterpolation>::deserialize(deserializer)
                }
                "output" => output = <usize>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            input: input?,
            interpolation: interpolation,
            output: output?,
            extensions: extensions,
        })
    }
}

/// Interpolation algorithm.
#[derive(Debug, Clone)]
pub enum AnimationSamplerInterpolation {
    /// The animated values are linearly interpolated between keyframes. When targeting a rotation, spherical linear interpolation (slerp) should be used to interpolate quaternions. The number output of elements must equal the number of input elements.
    Linear,
    /// The animated values remain constant to the output of the first keyframe, until the next keyframe. The number of output elements must equal the number of input elements.
    Step,
    /// The animation's interpolation is computed using a cubic spline with specified tangents. The number of output elements must equal three times the number of input elements. For each input element, the output stores three elements, an in-tangent, a spline vertex, and an out-tangent. There must be at least two keyframes when using this interpolation.
    Cubicspline,
}

impl Serialize for AnimationSamplerInterpolation {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Linear => "LINEAR".serialize(serializer),
            Self::Step => "STEP".serialize(serializer),
            Self::Cubicspline => "CUBICSPLINE".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for AnimationSamplerInterpolation {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "LINEAR" => Self::Linear,
            "STEP" => Self::Step,
            "CUBICSPLINE" => Self::Cubicspline,
            _ => None?,
        })
    }
}

/// Targets an animation's sampler at a node's property.
#[derive(Debug, Clone)]
pub struct AnimationChannel {
    /// The index of a sampler in this animation used to compute the value for the target.
    pub sampler: usize,
    /// The index of the node and TRS property to target.
    pub target: AnimationChannelTarget,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AnimationChannel {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("sampler", &self.sampler);
        object.property("target", &self.target);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AnimationChannel {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut sampler = None;
        let mut target = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "sampler" => sampler = <usize>::deserialize(deserializer),
                "target" => target = <AnimationChannelTarget>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            sampler: sampler?,
            target: target?,
            extensions: extensions,
        })
    }
}

/// The index of the node and TRS property to target.
#[derive(Debug, Clone)]
pub struct AnimationChannelTarget {
    /// The index of the node to target.
    pub node: Option<usize>,
    /// The name of the node's TRS property to modify, or the "weights" of the Morph Targets it instantiates. For the "translation" property, the values that are provided by the sampler are the translation along the x, y, and z axes. For the "rotation" property, the values are a quaternion in the order (x, y, z, w), where w is the scalar. For the "scale" property, the values are the scaling factors along the x, y, and z axes.
    pub path: AnimationChannelTargetPath,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AnimationChannelTarget {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.node.as_ref() {
            object.property("node", v);
        }
        object.property("path", &self.path);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AnimationChannelTarget {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut node = None;
        let mut path = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "node" => node = <usize>::deserialize(deserializer),
                "path" => path = <AnimationChannelTargetPath>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            node: node,
            path: path?,
            extensions: extensions,
        })
    }
}

/// The name of the node's TRS property to modify, or the "weights" of the Morph Targets it instantiates. For the "translation" property, the values that are provided by the sampler are the translation along the x, y, and z axes. For the "rotation" property, the values are a quaternion in the order (x, y, z, w), where w is the scalar. For the "scale" property, the values are the scaling factors along the x, y, and z axes.
#[derive(Debug, Clone)]
pub enum AnimationChannelTargetPath {
    Translation,
    Rotation,
    Scale,
    Weights,
}

impl Serialize for AnimationChannelTargetPath {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Translation => "translation".serialize(serializer),
            Self::Rotation => "rotation".serialize(serializer),
            Self::Scale => "scale".serialize(serializer),
            Self::Weights => "weights".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for AnimationChannelTargetPath {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "translation" => Self::Translation,
            "rotation" => Self::Rotation,
            "scale" => Self::Scale,
            "weights" => Self::Weights,
            _ => None?,
        })
    }
}

/// 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.
#[derive(Debug, Clone)]
pub struct Accessor {
    /// The index of the bufferView.
    pub buffer_view: Option<usize>,
    /// The offset relative to the start of the bufferView in bytes.
    pub byte_offset: Option<usize>,
    /// The datatype of components in the attribute.
    pub component_type: AccessorComponentType,
    /// Specifies whether integer data values should be normalized.
    pub normalized: Option<bool>,
    /// The number of attributes referenced by this accessor.
    pub count: usize,
    /// Specifies if the attribute is a scalar, vector, or matrix.
    pub type_: AccessorType,
    /// Maximum value of each component in this attribute.
    pub max: Vec<f32>,
    /// Minimum value of each component in this attribute.
    pub min: Vec<f32>,
    /// Sparse storage of attributes that deviate from their initialization value.
    pub sparse: Option<AccessorSparse>,
    /// The user-defined name of this object.
    pub name: Option<String>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for Accessor {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        if let Some(v) = self.buffer_view.as_ref() {
            object.property("bufferView", v);
        }
        if let Some(v) = self.byte_offset.as_ref() {
            object.property("byteOffset", v);
        }
        object.property("componentType", &self.component_type);
        if let Some(v) = self.normalized.as_ref() {
            object.property("normalized", v);
        }
        object.property("count", &self.count);
        object.property("type", &self.type_);
        if !self.max.is_empty() {
            object.property("max", &self.max);
        }
        if !self.min.is_empty() {
            object.property("min", &self.min);
        }
        if let Some(v) = self.sparse.as_ref() {
            object.property("sparse", v);
        }
        if let Some(v) = self.name.as_ref() {
            object.property("name", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Accessor {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut buffer_view = None;
        let mut byte_offset = None;
        let mut component_type = None;
        let mut normalized = None;
        let mut count = None;
        let mut type_ = None;
        let mut max = None;
        let mut min = None;
        let mut sparse = None;
        let mut name = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "bufferView" => buffer_view = <usize>::deserialize(deserializer),
                "byteOffset" => byte_offset = <usize>::deserialize(deserializer),
                "componentType" => {
                    component_type = <AccessorComponentType>::deserialize(deserializer)
                }
                "normalized" => normalized = <bool>::deserialize(deserializer),
                "count" => count = <usize>::deserialize(deserializer),
                "type" => type_ = <AccessorType>::deserialize(deserializer),
                "max" => max = <Vec<f32>>::deserialize(deserializer),
                "min" => min = <Vec<f32>>::deserialize(deserializer),
                "sparse" => sparse = <AccessorSparse>::deserialize(deserializer),
                "name" => name = <String>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            buffer_view: buffer_view,
            byte_offset: byte_offset,
            component_type: component_type?,
            normalized: normalized,
            count: count?,
            type_: type_?,
            max: max.unwrap_or_else(|| Vec::new()),
            min: min.unwrap_or_else(|| Vec::new()),
            sparse: sparse,
            name: name,
            extensions: extensions,
        })
    }
}

/// Sparse storage of attributes that deviate from their initialization value.
#[derive(Debug, Clone)]
pub struct AccessorSparse {
    /// Number of entries stored in the sparse array.
    pub count: usize,
    /// Index array of size `count` that points to those accessor attributes that deviate from their initialization value. Indices must strictly increase.
    pub indices: AccessorSparseIndices,
    /// 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.
    pub values: AccessorSparseValues,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AccessorSparse {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("count", &self.count);
        object.property("indices", &self.indices);
        object.property("values", &self.values);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AccessorSparse {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut count = None;
        let mut indices = None;
        let mut values = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "count" => count = <usize>::deserialize(deserializer),
                "indices" => indices = <AccessorSparseIndices>::deserialize(deserializer),
                "values" => values = <AccessorSparseValues>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            count: count?,
            indices: indices?,
            values: values?,
            extensions: extensions,
        })
    }
}

/// 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.
#[derive(Debug, Clone)]
pub struct AccessorSparseValues {
    /// The index of the bufferView with sparse values. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target.
    pub buffer_view: usize,
    /// The offset relative to the start of the bufferView in bytes. Must be aligned.
    pub byte_offset: Option<usize>,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AccessorSparseValues {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("bufferView", &self.buffer_view);
        if let Some(v) = self.byte_offset.as_ref() {
            object.property("byteOffset", v);
        }
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AccessorSparseValues {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut buffer_view = None;
        let mut byte_offset = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "bufferView" => buffer_view = <usize>::deserialize(deserializer),
                "byteOffset" => byte_offset = <usize>::deserialize(deserializer),
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            buffer_view: buffer_view?,
            byte_offset: byte_offset,
            extensions: extensions,
        })
    }
}

/// Index array of size `count` that points to those accessor attributes that deviate from their initialization value. Indices must strictly increase.
#[derive(Debug, Clone)]
pub struct AccessorSparseIndices {
    /// The index of the bufferView with sparse indices. Referenced bufferView can't have ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target.
    pub buffer_view: usize,
    /// The offset relative to the start of the bufferView in bytes. Must be aligned.
    pub byte_offset: Option<usize>,
    /// The indices data type.
    pub component_type: AccessorSparseIndicesComponentType,
    /// Dictionary object with extension-specific objects.
    pub extensions: Option<Extension>,
}

impl Serialize for AccessorSparseIndices {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let mut object = serializer.begin_object();
        object.property("bufferView", &self.buffer_view);
        if let Some(v) = self.byte_offset.as_ref() {
            object.property("byteOffset", v);
        }
        object.property("componentType", &self.component_type);
        if let Some(v) = self.extensions.as_ref() {
            object.property("extensions", v);
        }
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for AccessorSparseIndices {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;
        let mut buffer_view = None;
        let mut byte_offset = None;
        let mut component_type = None;
        let mut extensions = None;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                "bufferView" => buffer_view = <usize>::deserialize(deserializer),
                "byteOffset" => byte_offset = <usize>::deserialize(deserializer),
                "componentType" => {
                    component_type = <AccessorSparseIndicesComponentType>::deserialize(deserializer)
                }
                "extensions" => extensions = <Extension>::deserialize(deserializer),
                _ => {}
            }
        }

        Some(Self {
            buffer_view: buffer_view?,
            byte_offset: byte_offset,
            component_type: component_type?,
            extensions: extensions,
        })
    }
}

/// Dictionary object with extension-specific objects.
#[derive(Debug, Clone)]
pub struct Extension {}

impl Serialize for Extension {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        let object = serializer.begin_object();
        object.end_object();
    }
}
impl<'a> Deserialize<'a> for Extension {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        deserializer.begin_object().then(|| {})?;

        while let Some(property) = deserializer.has_property() {
            match &*property {
                _ => {}
            }
        }

        Some(Self {})
    }
}

/// The indices data type.
#[derive(Debug, Clone)]
pub enum AccessorSparseIndicesComponentType {
    UnsignedByte,
    UnsignedShort,
    UnsignedInt,
}

impl Serialize for AccessorSparseIndicesComponentType {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::UnsignedByte => 5121.serialize(serializer),
            Self::UnsignedShort => 5123.serialize(serializer),
            Self::UnsignedInt => 5125.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for AccessorSparseIndicesComponentType {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            5121 => Self::UnsignedByte,
            5123 => Self::UnsignedShort,
            5125 => Self::UnsignedInt,
            _ => None?,
        })
    }
}

/// Specifies if the attribute is a scalar, vector, or matrix.
#[derive(Debug, Clone)]
pub enum AccessorType {
    Scalar,
    Vec2,
    Vec3,
    Vec4,
    Mat2,
    Mat3,
    Mat4,
}

impl Serialize for AccessorType {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Scalar => "SCALAR".serialize(serializer),
            Self::Vec2 => "VEC2".serialize(serializer),
            Self::Vec3 => "VEC3".serialize(serializer),
            Self::Vec4 => "VEC4".serialize(serializer),
            Self::Mat2 => "MAT2".serialize(serializer),
            Self::Mat3 => "MAT3".serialize(serializer),
            Self::Mat4 => "MAT4".serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for AccessorType {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.string()?;
        Some(match &*value {
            "SCALAR" => Self::Scalar,
            "VEC2" => Self::Vec2,
            "VEC3" => Self::Vec3,
            "VEC4" => Self::Vec4,
            "MAT2" => Self::Mat2,
            "MAT3" => Self::Mat3,
            "MAT4" => Self::Mat4,
            _ => None?,
        })
    }
}

/// The datatype of components in the attribute.
#[derive(Debug, Clone)]
pub enum AccessorComponentType {
    Byte,
    UnsignedByte,
    Short,
    UnsignedShort,
    UnsignedInt,
    Float,
}

impl Serialize for AccessorComponentType {
    fn serialize<S: Serializer>(&self, serializer: &mut S) {
        match self {
            Self::Byte => 5120.serialize(serializer),
            Self::UnsignedByte => 5121.serialize(serializer),
            Self::Short => 5122.serialize(serializer),
            Self::UnsignedShort => 5123.serialize(serializer),
            Self::UnsignedInt => 5125.serialize(serializer),
            Self::Float => 5126.serialize(serializer),
        }
    }
}
impl<'a> Deserialize<'a> for AccessorComponentType {
    fn deserialize<D: Deserializer<'a>>(deserializer: &mut D) -> Option<Self> {
        let value = deserializer.i64()?;
        Some(match value {
            5120 => Self::Byte,
            5121 => Self::UnsignedByte,
            5122 => Self::Short,
            5123 => Self::UnsignedShort,
            5125 => Self::UnsignedInt,
            5126 => Self::Float,
            _ => None?,
        })
    }
}