summaryrefslogtreecommitdiffstats
path: root/src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp
blob: b4f598010b9fb530c94e2f8042aacd5d02a2c736 (plain)
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
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "EnginePrefix.h"
#include "Qt3DSRenderRuntimeBindingImpl.h"
#include "Qt3DSRenderUIPSharedTranslation.h"
#include "Qt3DSRenderBufferManager.h"
#include "foundation/SerializationTypes.h"
#include "StringTools.h"
#include "foundation/FileTools.h"
#include "Qt3DSHash.h"
#include "Qt3DSRenderPlugin.h"
#include "Qt3DSRenderPluginPropertyValue.h"
#include "Qt3DSElementHelper.h"
#include "Qt3DSPresentation.h"
#include "Qt3DSApplication.h"
#include "Qt3DSRenderCustomMaterialSystem.h"
#include "Qt3DSRenderPath.h"
#include "Qt3DSRenderPathSubPath.h"
#include "Qt3DSRenderPathManager.h"

using namespace qt3ds::foundation;

namespace Q3DStudio {
enum ExtendedAttributes {
    ATTRIBUTE_NONE = 0,
    ATTRIBUTE_NONE_R,
    ATTRIBUTE_NONE_G,
    ATTRIBUTE_NONE_B
};
}

namespace {
QT3DSU32 g_TranslatorTag;
QT3DSU32 g_PresentationTag;
}

// Add specializations for the tagged pointer operations to make casting
// a bit safer and more transparent.
namespace qt3ds {
namespace render {
    template <>
    struct SPointerTag<Qt3DSTranslator>
    {
        static QT3DSU32 GetTag() { return g_TranslatorTag; }
    };
    template <>
    struct SPointerTag<Q3DStudio::IPresentation>
    {
        static QT3DSU32 GetTag() { return g_PresentationTag; }
    };
}
}

namespace {

template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
struct SDirtySetter
{
};

template <>
struct SDirtySetter<Qt3DSRenderDirtyFlags::Dirty>
{
    static void Set(bool &dirty, bool & /*transformDirty*/, bool & /*textDirty*/) { dirty = true; }
};
template <>
struct SDirtySetter<Qt3DSRenderDirtyFlags::TransformDirty>
{
    static void Set(bool &dirty, bool &transformDirty, bool & /*textDirty*/)
    {
        dirty = true;
        transformDirty = true;
    }
};
template <>
struct SDirtySetter<Qt3DSRenderDirtyFlags::TextDirty>
{
    static void Set(bool &dirty, bool & /*transformDirty*/, bool &textDirty)
    {
        dirty = true;
        textDirty = true;
    }
};
template <>
struct SDirtySetter<Qt3DSRenderDirtyFlags::Unknown>
{
    static void Set(bool & /*dirty*/, bool & /*transformDirty*/, bool & /*textDirty*/) {}
};

// Translates individual property values from the runtime into the rendering system.
struct SRuntimePropertyParser
{
    QT3DSI32 m_PropertyName;
    Q3DStudio::UVariant m_Value;
    Q3DStudio::EAttributeType m_Type;
    Q3DStudio::TElement &m_Element;
    SPresentation &m_Presentation;
    IQt3DSRenderContext &m_RenderContext;
    bool m_Dirty;
    bool m_TransformDirty;
    bool m_TextDirty;

    SRuntimePropertyParser(SPresentation &inPresentation, IQt3DSRenderContext &inRenderContext,
                           Q3DStudio::TElement &inElement)
        : m_PropertyName(0)
        , m_Type((Q3DStudio::EAttributeType)0)
        , m_Element(inElement)
        , m_Presentation(inPresentation)
        , m_RenderContext(inRenderContext)
        , m_Dirty(false)
        , m_TransformDirty(false)
        , m_TextDirty(false)
    {
    }

    void Setup(QT3DSI32 inPropName, Q3DStudio::UVariant inValue, Q3DStudio::EAttributeType inType)
    {
        m_PropertyName = inPropName;
        m_Value = inValue;
        m_Type = inType;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    void SetDirty()
    {
        SDirtySetter<TDirtyType>::Set(m_Dirty, m_TransformDirty, m_TextDirty);
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(QT3DSF32 &outValue)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_FLOAT) {
            QT3DSF32 newValue = m_Value.m_FLOAT;
            if (outValue != newValue) {
                outValue = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    };
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(QT3DSU32 &outValue)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_INT32) {
            QT3DSU32 newValue = (QT3DSU32)m_Value.m_INT32;
            if (outValue != newValue) {
                outValue = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    };
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(SGraphObject *&outValue)
    {
        Q3DStudio::TElement *theElem = NULL;
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_ELEMENTREF) {
            theElem = m_Element.GetBelongedPresentation()->GetApplication().GetElementByHandle(
                m_Value.m_ElementHandle);
        } else if (m_Type == Q3DStudio::ATTRIBUTETYPE_STRING) {
            CRegisteredString theString =
                m_RenderContext.GetStringTable().HandleToStr(m_Value.m_StringHandle);
            theElem = Q3DStudio::CElementHelper::GetElement(
                m_Element.GetBelongedPresentation()->GetApplication(),
                m_Element.GetBelongedPresentation(), theString.c_str(), &m_Element);
        }

        SGraphObject *newValue = NULL;
        if (theElem) {
            Qt3DSTranslator *theTranslator =
                reinterpret_cast<Qt3DSTranslator *>(theElem->GetAssociation());
            if (theTranslator)
                newValue = theTranslator->m_RenderObject;
        }
        if (outValue != newValue) {
            outValue = newValue;
            SetDirty<TDirtyType>();
            return true;
        }
        return false;
    };
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseRadianProperty(QT3DSF32 &outValue)
    {
        if (ParseProperty<TDirtyType>(outValue)) {
            TORAD(outValue);
            return true;
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseOpacityProperty(QT3DSF32 &outValue)
    {
        if (ParseProperty<TDirtyType>(outValue)) {
            outValue *= 1.0f / 100.0f;
            return true;
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseOrientationProperty(bool &ioCurrent)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_STRING) {
            CRegisteredString strValue =
                m_RenderContext.GetStringTable().HandleToStr(m_Value.m_StringHandle);
            bool newValue = AreEqual(strValue.c_str(), "Left Handed") ? true : false;
            if (ioCurrent != newValue) {
                ioCurrent = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(bool &ioCurrent)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_BOOL || m_Type == Q3DStudio::ATTRIBUTETYPE_INT32) {
            bool newValue = m_Value.m_INT32 ? true : false;
            if (ioCurrent != newValue) {
                ioCurrent = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseInverseBoolean(bool &ioCurrent)
    {
        bool temp = !ioCurrent;
        if (ParseProperty<TDirtyType>(temp)) {
            ioCurrent = temp;
            return true;
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(QT3DSVec3 &outValue)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_FLOAT3) {
            QT3DSVec3 newValue(m_Value.m_FLOAT3[0], m_Value.m_FLOAT3[1], m_Value.m_FLOAT3[2]);
            if (outValue != newValue) {
                outValue = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(QT3DSVec4 &outValue)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_FLOAT4) {
            QT3DSVec4 newValue(m_Value.m_FLOAT4[0], m_Value.m_FLOAT4[1], m_Value.m_FLOAT4[2],
                               m_Value.m_FLOAT4[3]);
            if (outValue != newValue) {
                outValue = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    }


    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(CRegisteredString &outValue)
    {
        if (m_Type == Q3DStudio::ATTRIBUTETYPE_STRING) {
            CRegisteredString newValue =
                m_RenderContext.GetStringTable().HandleToStr(m_Value.m_StringHandle);
            if (newValue.c_str() != outValue.c_str()) {
                outValue = newValue;
                SetDirty<TDirtyType>();
                return true;
            }
        } else {
            QT3DS_ASSERT(false);
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseRotationOrder(QT3DSU32 &outValue)
    {
        CRegisteredString theString;
        ParseProperty<Qt3DSRenderDirtyFlags::Unknown>(theString);
        if (theString.IsValid()) {
            QT3DSU32 newRotationOrder = MapRotationOrder(theString);
            if (newRotationOrder != outValue) {
                outValue = newRotationOrder;
                SetDirty<TDirtyType>();
                return true;
            }
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseOrientation(NodeFlags &outValue)
    {
        bool temp = false;
        ParseOrientationProperty<TDirtyType>(temp);
        bool wasLeftHanded = outValue.IsLeftHanded();
        if (wasLeftHanded != temp) {
            outValue.SetLeftHanded(temp);
            SetDirty<TDirtyType>();
            return true;
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseNodeFlagsProperty(NodeFlags &outValue, NodeFlagValues::Enum inFlag)
    {
        bool temp = false;
        ParseProperty<Qt3DSRenderDirtyFlags::Unknown>(temp);
        bool wasSet = outValue & inFlag;
        if (temp != wasSet) {
            outValue.ClearOrSet(temp, inFlag);
            SetDirty<TDirtyType>();
            return true;
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseNodeFlagsInverseProperty(NodeFlags &outValue, NodeFlagValues::Enum inFlag)
    {
        bool temp = false;
        ParseProperty<Qt3DSRenderDirtyFlags::Unknown>(temp);
        temp = !temp;
        bool wasSet = outValue & inFlag;
        if (temp != wasSet) {
            outValue.ClearOrSet(temp, inFlag);
            SetDirty<TDirtyType>();
            return true;
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType, typename TEnumType>
    bool ParseEnumProperty(TEnumType &outValue)
    {
        CRegisteredString theString;
        ParseProperty<Qt3DSRenderDirtyFlags::Unknown>(theString);
        if (theString.IsValid()) {
            SEnumNameMap *theMap = SEnumParseMap<TEnumType>::GetMap();
            for (SEnumNameMap *theItem = theMap; theItem->m_Name && *theItem->m_Name; ++theItem) {
                // hack to match advanced overlay types, whose name start with a '*'
                const char8_t *p = theString.c_str();
                if (*p == '*')
                    ++p;
                if (strcmp(p, theItem->m_Name) == 0) {
                    TEnumType theNewValue = static_cast<TEnumType>(theItem->m_Enum);
                    if (outValue != theNewValue) {
                        outValue = theNewValue;
                        SetDirty<TDirtyType>();
                        return true;
                    }
                }
            }
        }
        return false;
    }
    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseAndResolveSourcePath(CRegisteredString &outValue)
    {
        CRegisteredString theTemp;
        ParseProperty<Qt3DSRenderDirtyFlags::Unknown>(theTemp);
        CRegisteredString theNewStr = theTemp;
        if (outValue.c_str() != theNewStr.c_str()) {
            SetDirty<TDirtyType>();
            outValue = theNewStr;
            return true;
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(SImage *&ioImagePtr)
    {
        Q3DStudio::TElement *theElem =
            m_Element.GetBelongedPresentation()->GetApplication().GetElementByHandle(
                m_Value.m_ElementHandle);
        // Try to be very careful in here as casting things around like crazy is a sure
        // way to crash the runtime at a bad point.
        if (theElem != NULL) {
            Qt3DSTranslator *theTranslator =
                reinterpret_cast<Qt3DSTranslator *>(theElem->GetAssociation());
            if (theTranslator != NULL && theTranslator->GetUIPType() == GraphObjectTypes::Image) {
                SImage *theImage = static_cast<SImage *>(theTranslator->m_RenderObject);
                if (ioImagePtr != theImage) {
                    ioImagePtr = theImage;
                    SetDirty<TDirtyType>();
                    return true;
                }
            }
        }
        return false;
    }

    template <Qt3DSRenderDirtyFlags::Enum TDirtyType>
    bool ParseProperty(SNode *&ioNodePtr)
    {
        Q3DStudio::TElement *theElem =
            m_Element.GetBelongedPresentation()->GetApplication().GetElementByHandle(
                m_Value.m_ElementHandle);
        // Try to be very careful in here as casting things around like crazy is a sure
        // way to crash the runtime at a bad point.
        SNode *theNode = NULL;
        if (theElem != NULL
            && theElem->GetBelongedPresentation() == m_Element.GetBelongedPresentation()) {
            Qt3DSTranslator *theTranslator =
                reinterpret_cast<Qt3DSTranslator *>(theElem->GetAssociation());
            if (theTranslator != NULL
                && GraphObjectTypes::IsNodeType(theTranslator->GetUIPType())) {
                theNode = static_cast<SNode *>(theTranslator->m_RenderObject);
            }
        }
        if (ioNodePtr != theNode) {
            ioNodePtr = theNode;
            SetDirty<TDirtyType>();
            return true;
        }
        return false;
    }
};

// Fill out parse name table.
#define Scene_ClearColor_R ATTRIBUTE_BACKGROUNDCOLOR_R
#define Scene_ClearColor_G ATTRIBUTE_BACKGROUNDCOLOR_G
#define Scene_ClearColor_B ATTRIBUTE_BACKGROUNDCOLOR_B
#define Scene_ClearColor_A ATTRIBUTE_BACKGROUNDCOLOR_A
#define Scene_UseClearColor ATTRIBUTE_BGCOLORENABLE
#define Node_Rotation ATTRIBUTE_ROTATION
#define Node_Rotation_X ATTRIBUTE_ROTATION_X
#define Node_Rotation_Y ATTRIBUTE_ROTATION_Y
#define Node_Rotation_Z ATTRIBUTE_ROTATION_Z
#define Node_Position ATTRIBUTE_POSITION
#define Node_Position_X ATTRIBUTE_POSITION_X
#define Node_Position_Y ATTRIBUTE_POSITION_Y
#define Node_Position_Z ATTRIBUTE_POSITION_Z
#define Node_Scale ATTRIBUTE_SCALE
#define Node_Scale_X ATTRIBUTE_SCALE_X
#define Node_Scale_Y ATTRIBUTE_SCALE_Y
#define Node_Scale_Z ATTRIBUTE_SCALE_Z
#define Node_Pivot ATTRIBUTE_PIVOT
#define Node_Pivot_X ATTRIBUTE_PIVOT_X
#define Node_Pivot_Y ATTRIBUTE_PIVOT_Y
#define Node_Pivot_Z ATTRIBUTE_PIVOT_Z
#define Node_LocalOpacity ATTRIBUTE_OPACITY
#define Node_RotationOrder ATTRIBUTE_ROTATIONORDER
#define Node_LeftHanded ATTRIBUTE_ORIENTATION
#define Layer_TemporalAAEnabled ATTRIBUTE_TEMPORALAA
#define Layer_LayerEnableDepthTest ATTRIBUTE_DISABLEDEPTHTEST
#define Layer_LayerEnableDepthPrePass ATTRIBUTE_DISABLEDEPTHPREPASS
#define Layer_ClearColor_R ATTRIBUTE_BACKGROUNDCOLOR_R
#define Layer_ClearColor_G ATTRIBUTE_BACKGROUNDCOLOR_G
#define Layer_ClearColor_B ATTRIBUTE_BACKGROUNDCOLOR_B
#define Layer_ClearColor_A ATTRIBUTE_BACKGROUNDCOLOR_A
#define Layer_Background ATTRIBUTE_BACKGROUND
#define Layer_BlendType ATTRIBUTE_BLENDTYPE
#define Layer_ProgressiveAAMode ATTRIBUTE_PROGRESSIVEAA
#define Layer_MultisampleAAMode ATTRIBUTE_MULTISAMPLEAA
#define Layer_HorizontalFieldValues ATTRIBUTE_HORZFIELDS
#define Layer_Left ATTRIBUTE_LEFT
#define Layer_LeftUnits ATTRIBUTE_LEFTUNITS
#define Layer_Width ATTRIBUTE_WIDTH
#define Layer_WidthUnits ATTRIBUTE_WIDTHUNITS
#define Layer_Right ATTRIBUTE_RIGHT
#define Layer_RightUnits ATTRIBUTE_RIGHTUNITS
#define Layer_VerticalFieldValues ATTRIBUTE_VERTFIELDS
#define Layer_Top ATTRIBUTE_TOP
#define Layer_TopUnits ATTRIBUTE_TOPUNITS
#define Layer_Height ATTRIBUTE_HEIGHT
#define Layer_HeightUnits ATTRIBUTE_HEIGHTUNITS
#define Layer_Bottom ATTRIBUTE_BOTTOM
#define Layer_BottomUnits ATTRIBUTE_BOTTOMUNITS
#define Layer_AoStrength ATTRIBUTE_AOSTRENGTH
#define Layer_AoDistance ATTRIBUTE_AODISTANCE
#define Layer_AoSoftness ATTRIBUTE_AOSOFTNESS
#define Layer_AoBias ATTRIBUTE_AOBIAS
#define Layer_AoSamplerate ATTRIBUTE_AOSAMPLERATE
#define Layer_AoDither ATTRIBUTE_AODITHER
#define Layer_ShadowStrength ATTRIBUTE_SHADOWSTRENGTH
#define Layer_ShadowDist ATTRIBUTE_SHADOWDIST
#define Layer_ShadowSoftness ATTRIBUTE_SHADOWSOFTNESS
#define Layer_ShadowBias ATTRIBUTE_SHADOWBIAS
#define Layer_LightProbe ATTRIBUTE_LIGHTPROBE
#define Layer_ProbeBright ATTRIBUTE_PROBEBRIGHT
#define Layer_FastIbl ATTRIBUTE_FASTIBL
#define Layer_ProbeTheta ATTRIBUTE_PROBETHETA
#define Layer_ProbePhi ATTRIBUTE_PROBEPHI
#define Layer_ProbeHorizon ATTRIBUTE_PROBEHORIZON
#define Layer_LightProbe2 ATTRIBUTE_LIGHTPROBE2
#define Layer_Probe2Fade ATTRIBUTE_PROBE2FADE
#define Layer_Probe2Window ATTRIBUTE_PROBE2WINDOW
#define Layer_Probe2Pos ATTRIBUTE_PROBE2POS
#define Layer_ProbeFov ATTRIBUTE_PROBEFOV
#define Layer_TexturePath ATTRIBUTE_SOURCEPATH
#define Camera_ClipNear ATTRIBUTE_CLIPNEAR
#define Camera_ClipFar ATTRIBUTE_CLIPFAR
#define Camera_FOV ATTRIBUTE_FOV
#define Camera_FOVHorizontal ATTRIBUTE_FOVHORIZONTAL
#define Camera_Orthographic ATTRIBUTE_ORTHOGRAPHIC
#define Camera_ScaleMode ATTRIBUTE_SCALEMODE
#define Camera_ScaleAnchor ATTRIBUTE_SCALEANCHOR
#define Light_ImageSource ATTRIBUTE_IMAGESOURCE
#define Light_Scope ATTRIBUTE_SCOPE
#define Light_ImageSetsColor ATTRIBUTE_IMAGESETSCOLOR
#define Light_ImageSetsRotation ATTRIBUTE_IMAGESETSROTATION
#define Light_ImageHFov ATTRIBUTE_IMAGEHFOV
#define Light_ImageIsFisheye ATTRIBUTE_IMAGEISFISHEYE
#define Light_LightType ATTRIBUTE_LIGHTTYPE
#define Light_DiffuseColor ATTRIBUTE_LIGHTDIFFUSE
#define Light_DiffuseColor_R ATTRIBUTE_LIGHTDIFFUSE_R
#define Light_DiffuseColor_G ATTRIBUTE_LIGHTDIFFUSE_G
#define Light_DiffuseColor_B ATTRIBUTE_LIGHTDIFFUSE_B
#define Light_DiffuseColor_A ATTRIBUTE_LIGHTDIFFUSE_A
#define Light_SpecularColor ATTRIBUTE_LIGHTSPECULAR
#define Light_SpecularColor_R ATTRIBUTE_LIGHTSPECULAR_R
#define Light_SpecularColor_G ATTRIBUTE_LIGHTSPECULAR_G
#define Light_SpecularColor_B ATTRIBUTE_LIGHTSPECULAR_B
#define Light_SpecularColor_A ATTRIBUTE_LIGHTSPECULAR_A
#define Light_AmbientColor ATTRIBUTE_LIGHTAMBIENT
#define Light_AmbientColor_R ATTRIBUTE_LIGHTAMBIENT_R
#define Light_AmbientColor_G ATTRIBUTE_LIGHTAMBIENT_G
#define Light_AmbientColor_B ATTRIBUTE_LIGHTAMBIENT_B
#define Light_AmbientColor_A ATTRIBUTE_LIGHTAMBIENT_A
#define Light_Brightness ATTRIBUTE_BRIGHTNESS
#define Light_LinearFade ATTRIBUTE_LINEARFADE
#define Light_ExponentialFade ATTRIBUTE_EXPFADE
#define Light_AreaWidth ATTRIBUTE_AREAWIDTH
#define Light_AreaHeight ATTRIBUTE_AREAHEIGHT
#define Light_CastShadow ATTRIBUTE_CASTSHADOW
#define Light_ShadowBias ATTRIBUTE_SHDWBIAS
#define Light_ShadowFactor ATTRIBUTE_SHDWFACTOR
#define Light_ShadowMapRes ATTRIBUTE_SHDWMAPRES
#define Light_ShadowMapFar ATTRIBUTE_SHDWMAPFAR
#define Light_ShadowMapFov ATTRIBUTE_SHDWMAPFOV
#define Light_ShadowFilter ATTRIBUTE_SHDWFILTER
#define Model_MeshPath ATTRIBUTE_SOURCEPATH
#define Model_ShadowCaster ATTRIBUTE_SHADOWCASTER
#define Model_TessellationMode ATTRIBUTE_TESSELLATION
#define Model_EdgeTess ATTRIBUTE_EDGETESS
#define Model_InnerTess ATTRIBUTE_INNERTESS
#define Lightmaps_LightmapIndirect ATTRIBUTE_LIGHTMAPINDIRECT
#define Lightmaps_LightmapRadiosity ATTRIBUTE_LIGHTMAPRADIOSITY
#define Lightmaps_LightmapShadow ATTRIBUTE_LIGHTMAPSHADOW
#define Material_Lighting ATTRIBUTE_SHADERLIGHTING
#define Material_BlendMode ATTRIBUTE_BLENDMODE
#define MaterialBase_IblProbe ATTRIBUTE_IBLPROBE
#define Material_DiffuseColor ATTRIBUTE_DIFFUSE
#define Material_DiffuseColor_R ATTRIBUTE_DIFFUSE_R
#define Material_DiffuseColor_G ATTRIBUTE_DIFFUSE_G
#define Material_DiffuseColor_B ATTRIBUTE_DIFFUSE_B
#define Material_DiffuseColor_A ATTRIBUTE_DIFFUSE_A
#define Material_DiffuseMaps_0 ATTRIBUTE_DIFFUSEMAP
#define Material_DiffuseMaps_1 ATTRIBUTE_DIFFUSEMAP2
#define Material_DiffuseMaps_2 ATTRIBUTE_DIFFUSEMAP3
#define Material_EmissivePower ATTRIBUTE_EMISSIVEPOWER
#define Material_EmissiveColor ATTRIBUTE_EMISSIVECOLOR
#define Material_EmissiveColor_R ATTRIBUTE_EMISSIVECOLOR_R
#define Material_EmissiveColor_G ATTRIBUTE_EMISSIVECOLOR_G
#define Material_EmissiveColor_B ATTRIBUTE_EMISSIVECOLOR_B
#define Material_EmissiveColor_A ATTRIBUTE_EMISSIVECOLOR_A
#define Material_EmissiveMap ATTRIBUTE_EMISSIVEMAP
#define Material_EmissiveMap2 ATTRIBUTE_EMISSIVEMAP2
#define Material_SpecularReflection ATTRIBUTE_SPECULARREFLECTION
#define Material_SpecularMap ATTRIBUTE_SPECULARMAP
#define Material_SpecularModel ATTRIBUTE_SPECULARMODEL
#define Material_SpecularTint ATTRIBUTE_SPECULARTINT
#define Material_SpecularTint_R ATTRIBUTE_SPECULARTINT_R
#define Material_SpecularTint_G ATTRIBUTE_SPECULARTINT_G
#define Material_SpecularTint_B ATTRIBUTE_SPECULARTINT_B
#define Material_SpecularTint_A ATTRIBUTE_SPECULARTINT_A
#define Material_IOR ATTRIBUTE_IOR
#define Material_FresnelPower ATTRIBUTE_FRESNELPOWER
#define Material_SpecularAmount ATTRIBUTE_SPECULARAMOUNT
#define Material_SpecularRoughness ATTRIBUTE_SPECULARROUGHNESS
#define Material_RoughnessMap ATTRIBUTE_ROUGHNESSMAP
#define Material_Opacity ATTRIBUTE_OPACITY
#define Material_OpacityMap ATTRIBUTE_OPACITYMAP
#define Material_BumpAmount ATTRIBUTE_BUMPAMOUNT
#define Material_BumpMap ATTRIBUTE_BUMPMAP
#define Material_NormalMap ATTRIBUTE_NORMALMAP
#define Material_DisplaceAmount ATTRIBUTE_DISPLACEAMOUNT
#define Material_DisplacementMap ATTRIBUTE_DISPLACEMENTMAP
#define Material_TranslucentFalloff ATTRIBUTE_TRANSLUCENTFALLOFF
#define Material_TranslucencyMap ATTRIBUTE_TRANSLUCENCYMAP
#define Material_DiffuseLightWrap ATTRIBUTE_DIFFUSELIGHTWRAP
#define Material_ReferencedMaterial ATTRIBUTE_REFERENCEDMATERIAL
#define Material_VertexColors ATTRIBUTE_VERTEXCOLORS
#define Image_ImagePath ATTRIBUTE_SOURCEPATH
#define Image_OffscreenRendererId ATTRIBUTE_SUBPRESENTATION
#define Image_Scale_X ATTRIBUTE_SCALEU
#define Image_Scale_Y ATTRIBUTE_SCALEV
#define Image_Pivot_X ATTRIBUTE_PIVOTU
#define Image_Pivot_Y ATTRIBUTE_PIVOTV
#define Image_Rotation ATTRIBUTE_ROTATIONUV
#define Image_Position_X ATTRIBUTE_POSITIONU
#define Image_Position_Y ATTRIBUTE_POSITIONV
#define Image_MappingMode ATTRIBUTE_MAPPINGMODE
#define Image_HorizontalTilingMode ATTRIBUTE_TILINGMODEHORZ
#define Image_VerticalTilingMode ATTRIBUTE_TILINGMODEVERT
#define Text_Text ATTRIBUTE_TEXTSTRING
#define Text_Font ATTRIBUTE_FONT
#define Text_FontSize ATTRIBUTE_SIZE
#define Text_HorizontalAlignment ATTRIBUTE_HORZALIGN
#define Text_VerticalAlignment ATTRIBUTE_VERTALIGN
#define Text_Leading ATTRIBUTE_LEADING
#define Text_Tracking ATTRIBUTE_TRACKING
#define Text_DropShadow ATTRIBUTE_DROPSHADOW
#define Text_DropShadowStrength ATTRIBUTE_DROPSHADOWSTRENGTH
#define Text_DropShadowOffsetX ATTRIBUTE_DROPSHADOWOFFSETX
#define Text_DropShadowOffsetY ATTRIBUTE_DROPSHADOWOFFSETY
#define Text_WordWrap ATTRIBUTE_WORDWRAP
#define Text_BoundingBox ATTRIBUTE_BOUNDINGBOX
#define Text_BoundingBox_X ATTRIBUTE_BOUNDINGBOX_X
#define Text_BoundingBox_Y ATTRIBUTE_BOUNDINGBOX_Y
#define Text_Elide ATTRIBUTE_ELIDE
#define Text_TextColor ATTRIBUTE_TEXTCOLOR
#define Text_TextColor_R ATTRIBUTE_TEXTCOLOR_R
#define Text_TextColor_G ATTRIBUTE_TEXTCOLOR_G
#define Text_TextColor_B ATTRIBUTE_TEXTCOLOR_B
#define Text_TextColor_A ATTRIBUTE_TEXTCOLOR_A
#define Text_BackColor_R ATTRIBUTE_BACKCOLOR_R
#define Text_BackColor_G ATTRIBUTE_BACKCOLOR_G
#define Text_BackColor_B ATTRIBUTE_BACKCOLOR_B
#define Text_BackColor_A ATTRIBUTE_BACKCOLOR_A
#define Text_UseBackColor ATTRIBUTE_USEBACKCOLOR
#define Text_EnableAcceleratedFont ATTRIBUTE_ENABLEACCELERATEDFONT
#define Path_PathType ATTRIBUTE_PATHTYPE
#define Path_Width ATTRIBUTE_WIDTH
#define Path_LinearError ATTRIBUTE_LINEARERROR
#define Path_EdgeTessAmount ATTRIBUTE_EDGETESSAMOUNT
#define Path_InnerTessAmount ATTRIBUTE_INNERTESSAMOUNT
#define Path_BeginCapping ATTRIBUTE_BEGINCAP
#define Path_BeginCapOffset ATTRIBUTE_BEGINCAPOFFSET
#define Path_BeginCapOpacity ATTRIBUTE_BEGINCAPOPACITY
#define Path_BeginCapWidth ATTRIBUTE_BEGINCAPWIDTH
#define Path_EndCapping ATTRIBUTE_ENDCAP
#define Path_EndCapOffset ATTRIBUTE_ENDCAPOFFSET
#define Path_EndCapOpacity ATTRIBUTE_ENDCAPOPACITY
#define Path_EndCapWidth ATTRIBUTE_ENDCAPWIDTH
#define Path_PaintStyle ATTRIBUTE_PAINTSTYLE
#define Path_PathBuffer ATTRIBUTE_SOURCEPATH
#define SubPath_Closed ATTRIBUTE_CLOSED

// Fill in implementations for the actual parse tables.
#define HANDLE_QT3DS_RENDER_PROPERTY(type, name, dirty)                                            \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);                    \
        break;

#define HANDLE_QT3DS_RENDER_VEC3_PROPERTY(type, name, dirty)                                       \
    case Q3DStudio::type##_##name##_X:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.x);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Y:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.y);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Z:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.z);                  \
        break;

#define HANDLE_QT3DS_RENDER_REAL_VEC2_PROPERTY(type, name, dirty)                                  \
    case Q3DStudio::type##_##name##_X:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.x);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Y:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.y);                  \
        break;

#define HANDLE_QT3DS_RENDER_COLOR_PROPERTY(type, name, dirty)                                      \
    case Q3DStudio::type##_##name##_R:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.x);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_G:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.y);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_B:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.z);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_A:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.w);                  \
        break;

#define HANDLE_QT3DS_RENDER_COLOR_VEC3_PROPERTY(type, name, dirty)                                 \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);                    \
        break;

#define HANDLE_QT3DS_RENDER_TRANSFORM_VEC3_PROPERTY(type, name, dirty)                             \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);                    \
        break;

#define HANDLE_QT3DS_RENDER_RADIAN_PROPERTY(type, name, dirty)                                     \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseRadianProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);              \
        break;

// The runtime converts rotations for us.
#define HANDLE_QT3DS_RENDER_VEC3_RADIAN_PROPERTY(type, name, dirty)                                \
    case Q3DStudio::type##_##name##_X:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.x);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Y:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.y);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Z:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.z);                  \
        break;

#define HANDLE_QT3DS_RENDER_OPACITY_PROPERTY(type, name, dirty)                                    \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseOpacityProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);             \
        break;

#define HANDLE_QT3DS_ROTATION_ORDER_PROPERTY(type, name, dirty)                                    \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseRotationOrder<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);               \
        break;

#define HANDLE_QT3DS_NODE_ORIENTATION_PROPERTY(type, name, dirty)                                  \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseOrientation<Qt3DSRenderDirtyFlags::dirty>(theItem.m_Flags);                  \
        break;

#define HANDLE_QT3DS_RENDER_DEPTH_TEST_PROPERTY(type, name, dirty)                                 \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseInverseBoolean<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);              \
        break;

#define HANDLE_QT3DS_NODE_FLAGS_PROPERTY(type, name, dirty)                                        \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseNodeFlagsProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_Flags,             \
                                                                    NodeFlagValues::name);         \
        break;

#define HANDLE_QT3DS_NODE_FLAGS_INVERSE_PROPERTY(type, name, dirty)                                \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseNodeFlagsInverseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_Flags,      \
                                                                           NodeFlagValues::name);  \
        break;

#define HANDLE_QT3DS_RENDER_ENUM_PROPERTY(type, name, dirty)                                       \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseEnumProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);                \
        break;

#define HANDLE_QT3DS_RENDER_SOURCEPATH_PROPERTY(type, name, dirty)                                 \
    case Q3DStudio::type##_##name:                                                                 \
        inParser.ParseAndResolveSourcePath<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name);        \
        break;

#define HANDLE_QT3DS_RENDER_ARRAY_PROPERTY(type, name, index, dirty)                               \
    case Q3DStudio::type##_##name##_##index:                                                       \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name[index]);             \
        break;

#define HANDLE_QT3DS_RENDER_VEC2_PROPERTY(type, name, dirty)                                       \
    case Q3DStudio::type##_##name##_X:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.x);                  \
        break;                                                                                     \
    case Q3DStudio::type##_##name##_Y:                                                             \
        inParser.ParseProperty<Qt3DSRenderDirtyFlags::dirty>(theItem.m_##name.y);                  \
        break;

struct SSceneTranslator : public Qt3DSTranslator
{
    typedef SScene TNodeType;
    SSceneTranslator(Q3DStudio::TElement &inElement, SScene &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
    }
    // Ignored, scenes are always active
    void SetActive(bool /*inElementActive*/) {}
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SScene &theItem = *static_cast<SScene *>(m_RenderObject);

        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_SCENE_PROPERTIES
        // These are ignored by the renderer
        case Q3DStudio::ATTRIBUTE_NAME:
        case Q3DStudio::ATTRIBUTE_STARTTIME:
        case Q3DStudio::ATTRIBUTE_ENDTIME:
        case Q3DStudio::ATTRIBUTE_IMPORTID:
        case Q3DStudio::ATTRIBUTE_EYEBALL:
            break;
        default:
            // Unknown attribute
            // QT3DS_ASSERT( false );
            break;
        }
    }
    void PostPropertyChanged(const SRuntimePropertyParser &, Q3DStudio::IPresentation &) {}
};

struct SNodeTranslator : public Qt3DSTranslator
{
    typedef SNode TNodeType;
    SNodeTranslator(Q3DStudio::TElement &inElement, SNode &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
        SNode &theItem = *static_cast<SNode *>(m_RenderObject);
        theItem.m_Flags.SetLocallyPickable(false);
    }
    void SetActive(bool inElementActive)
    {
        SNode &theItem = *static_cast<SNode *>(m_RenderObject);
        if (theItem.m_Flags.IsActive() != inElementActive) {
            theItem.m_Flags.SetActive(inElementActive);
            theItem.MarkDirty(NodeTransformDirtyFlag::TransformIsDirty);
        }
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SNode &theItem = *static_cast<SNode *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_NODE_PROPERTIES
        case Q3DStudio::ATTRIBUTE_NAME:
        case Q3DStudio::ATTRIBUTE_STARTTIME:
        case Q3DStudio::ATTRIBUTE_ENDTIME:
        case Q3DStudio::ATTRIBUTE_IMPORTID:
        case Q3DStudio::ATTRIBUTE_EYEBALL:
        // Groups have a source path property on them that we like to ignore.
        case Q3DStudio::ATTRIBUTE_SOURCEPATH:
            break;
        default:
            // Unknown attribute
            // QT3DS_ASSERT( false );
            break;
        }
    }
    void PostPropertyChanged(const SRuntimePropertyParser &inParser,
                             Q3DStudio::IPresentation & /*inStudioPresentation*/)
    {
        SNode &theItem = *static_cast<SNode *>(m_RenderObject);
        if (inParser.m_TransformDirty)
            theItem.MarkDirty(NodeTransformDirtyFlag::TransformIsDirty);
        else if (inParser.m_Dirty)
            theItem.MarkDirty(NodeTransformDirtyFlag::TransformNotDirty);
        if (inParser.m_TextDirty)
            theItem.m_Flags.SetTextDirty(true);
        SetActive(Element().GetActive());
        bool isNodePickable = m_Element->IsPickEnabled();
        if (theItem.m_Flags.IsLocallyPickable() != isNodePickable) {
            theItem.m_Flags.SetLocallyPickable(isNodePickable);
            theItem.MarkDirty(NodeTransformDirtyFlag::TransformNotDirty);
        }
    }
};

struct SLayerTranslator : public SNodeTranslator
{
    typedef SLayer TNodeType;
    SLayerTranslator(Q3DStudio::TElement &inElement, SLayer &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        const char *propName =
            Q3DStudio::GetAttributeString((Q3DStudio::EAttribute)inParser.m_PropertyName);
        (void)propName;
        SLayer &theItem = *static_cast<SLayer *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_LAYER_PROPERTIES
        // Ignored
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
        }
    }
};

struct SLightTranslator : public SNodeTranslator
{
    typedef SLight TNodeType;
    SLightTranslator(Q3DStudio::TElement &inElement, SLight &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SLight &theItem = *static_cast<SLight *>(m_RenderObject);
        // I guess there is no switching of light type in the runtime right now.
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_LIGHT_PROPERTIES
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
            break;
        }
    }
};
struct SCameraTranslator : public SNodeTranslator
{
    typedef SCamera TNodeType;
    SCameraTranslator(Q3DStudio::TElement &inElement, SCamera &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SCamera &theItem = *static_cast<SCamera *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_CAMERA_PROPERTIES
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
            break;
        }
    }
};

struct SModelTranslator : public SNodeTranslator
{
    typedef SModel TNodeType;
    SModelTranslator(Q3DStudio::TElement &inElement, SModel &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SModel &theItem = *static_cast<SModel *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_MODEL_PROPERTIES
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
            break;
        }
    }
};

struct SPathTranslator : public SNodeTranslator
{
    typedef SPath TNodeType;
    SPathTranslator(Q3DStudio::TElement &inElement, SPath &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SPath &theItem = *static_cast<SPath *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_PATH_PROPERTIES
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
            break;
        }
    }
};

struct SPathSubPathTranslator : public Qt3DSTranslator
{

    typedef SPathSubPath TNodeType;

    SPathSubPathTranslator(Q3DStudio::TElement &inElement, SPathSubPath &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SPathSubPath &theItem = *static_cast<SPathSubPath *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_PATH_SUBPATH_PROPERTIES
        default:
            break;
        }
    }

    void PostPropertyChanged(const SRuntimePropertyParser &inParser,
                             Q3DStudio::IPresentation & /*inStudioPresentation*/)
    {
        SPathSubPath &theItem = *static_cast<SPathSubPath *>(m_RenderObject);
        qt3ds::render::IPathManager &theManager = inParser.m_RenderContext.GetPathManager();
        QT3DSU32 numAnchors = 0;
        bool updatePath = false;
        CRegisteredString theAnchorType =
            inParser.m_RenderContext.GetStringTable().RegisterStr("PathAnchorPoint");
        for (Q3DStudio::TElement *theChild = Element().GetChild(); theChild;
             theChild = theChild->GetSibling()) {
            if (theChild->GetType() == theAnchorType) {
                ++numAnchors;
                if (theChild->IsDirty())
                    updatePath = true;
            }
        }
        if (updatePath) {
            NVDataRef<qt3ds::render::SPathAnchorPoint> thePathBuffer =
                theManager.ResizePathSubPathBuffer(theItem, numAnchors);
            if (thePathBuffer.size()) {
                QT3DSU32 anchorIndex = 0;
                for (Q3DStudio::TElement *theChild = Element().GetChild(); theChild;
                     theChild = theChild->GetSibling()) {
                    if (theChild->GetType() == theAnchorType) {
                        if (theChild->IsDirty()) {
                            qt3ds::render::SPathAnchorPoint &thePoint(thePathBuffer[anchorIndex]);

                            for (QT3DSI32 idx = 0, end = theChild->GetAttributeCount(); idx < end;
                                 ++idx) {
                                qt3ds::runtime::element::TPropertyDescAndValuePtr thePropInfo =
                                    theChild->GetPropertyByIndex(idx);
                                switch (thePropInfo.first.GetNameHash()) {
                                case Q3DStudio::ATTRIBUTE_POSITION_X:
                                    thePoint.m_Position.x = thePropInfo.second->m_FLOAT;
                                    break;
                                case Q3DStudio::ATTRIBUTE_POSITION_Y:
                                    thePoint.m_Position.y = thePropInfo.second->m_FLOAT;
                                    break;
                                case Q3DStudio::ATTRIBUTE_INCOMINGANGLE:
                                    thePoint.m_IncomingAngle = thePropInfo.second->m_FLOAT;
                                    thePoint.m_OutgoingAngle = thePoint.m_IncomingAngle + 180.0f;
                                    break;
                                case Q3DStudio::ATTRIBUTE_INCOMINGDISTANCE:
                                    thePoint.m_IncomingDistance = thePropInfo.second->m_FLOAT;
                                    break;
                                case Q3DStudio::ATTRIBUTE_OUTGOINGDISTANCE:
                                    thePoint.m_OutgoingDistance = thePropInfo.second->m_FLOAT;
                                    break;
                                default: // ignored
                                    break;
                                }
                            }
                        }
                        ++anchorIndex;
                    }
                }
            }
        }
    }
};

struct SDefaultMaterialTranslator : public Qt3DSTranslator
{
    typedef SDefaultMaterial TNodeType;
    SDefaultMaterialTranslator(Q3DStudio::TElement &inElement, SDefaultMaterial &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
    }
    // Right now materials do not respect the active flag
    void SetActive(bool) {}
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SDefaultMaterial &theItem = *static_cast<SDefaultMaterial *>(m_RenderObject);
        // There is no render-time caching on a material, so the dirty flag doesn't do much.
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_MATERIAL_PROPERTIES

        case Q3DStudio::ATTRIBUTE_NAME:
        case Q3DStudio::ATTRIBUTE_STARTTIME:
        case Q3DStudio::ATTRIBUTE_ENDTIME:
        case Q3DStudio::ATTRIBUTE_IMPORTID:
        case Q3DStudio::ATTRIBUTE_EYEBALL:
        case Q3DStudio::ATTRIBUTE_SOURCEPATH:
            break;
        default:
            // Unknown attribute
            // QT3DS_ASSERT( false );
            break;
        }
    }

    void PostPropertyChanged(const SRuntimePropertyParser &, Q3DStudio::IPresentation &)
    {
        SDefaultMaterial &theItem = *static_cast<SDefaultMaterial *>(m_RenderObject);
        theItem.m_Dirty.SetDirty();
    }
};

struct SImageTranslator : public Qt3DSTranslator
{
    typedef SImage TNodeType;
    SImageTranslator(Q3DStudio::TElement &inElement, SImage &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SImage &theItem = *static_cast<SImage *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_IMAGE_PROPERTIES
        case Q3DStudio::ATTRIBUTE_STARTTIME:
        case Q3DStudio::ATTRIBUTE_ENDTIME:
        case Q3DStudio::ATTRIBUTE_NAME:
        case Q3DStudio::ATTRIBUTE_EYEBALL:
            break;
        default:
            // Unknown attribute
            // QT3DS_ASSERT( false );
            break;
        }
    }
    void PostPropertyChanged(const SRuntimePropertyParser &inParser, Q3DStudio::IPresentation &)
    {
        SImage &theItem = *static_cast<SImage *>(m_RenderObject);
        if (inParser.m_Dirty)
            theItem.m_Flags.SetDirty(true);
        if (inParser.m_TransformDirty)
            theItem.m_Flags.SetTransformDirty(true);
    }
};

struct SReferencedMaterialTranslator : public Qt3DSTranslator
{
    typedef SReferencedMaterial TNodeType;
    SReferencedMaterialTranslator(Q3DStudio::TElement &inElement, TNodeType &inRenderObject)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
    }

    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        TNodeType &theItem = *static_cast<TNodeType *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_REFERENCED_MATERIAL_PROPERTIES
        case Q3DStudio::ATTRIBUTE_STARTTIME:
        case Q3DStudio::ATTRIBUTE_ENDTIME:
        case Q3DStudio::ATTRIBUTE_NAME:
        case Q3DStudio::ATTRIBUTE_EYEBALL:
            break;
        default:
            // Unknown attribute
            // QT3DS_ASSERT( false );
            break;
        }
    }
    void PostPropertyChanged(const SRuntimePropertyParser &inParser, Q3DStudio::IPresentation &)
    {
        TNodeType &theItem = *static_cast<TNodeType *>(m_RenderObject);
        if (inParser.m_Dirty)
            theItem.m_Dirty.SetDirty();
    }
};

struct STextTranslator : public SNodeTranslator
{
    typedef SText TNodeType;
    STextTranslator(Q3DStudio::TElement &inElement, SText &inRenderObject)
        : SNodeTranslator(inElement, inRenderObject)
    {
    }
    void OnSpecificPropertyChange(SRuntimePropertyParser &inParser)
    {
        SText &theItem = *static_cast<SText *>(m_RenderObject);
        switch (inParser.m_PropertyName) {
            ITERATE_QT3DS_RENDER_TEXT_PROPERTIES
        case Q3DStudio::ATTRIBUTE_TEXTTYPE:
        case Q3DStudio::ATTRIBUTE_RENDERSTYLE:
        case Q3DStudio::ATTRIBUTE_HORZSCROLL:
        case Q3DStudio::ATTRIBUTE_VERTSCROLL:
        case Q3DStudio::ATTRIBUTE_BOXHEIGHT:
        case Q3DStudio::ATTRIBUTE_BOXWIDTH:
        case Q3DStudio::ATTRIBUTE_REMOTESTRINGSOURCE:
        case Q3DStudio::ATTRIBUTE_CACHEDTEXTSTRING:
            // These text properties are ignored for now.
            break;
        default:
            SNodeTranslator::OnSpecificPropertyChange(inParser);
            break;
        }
    }
};

struct SEffectPropertyEntry
{
    Q3DStudio::EAttributeType m_AttributeType;
    QT3DSU32 m_PropertyOffset; // offset into the property array for the property def
    QT3DSU32 m_DataOffset;
    SEffectPropertyEntry(Q3DStudio::EAttributeType attType, QT3DSU32 poff, QT3DSU32 doff = 0)
        : m_AttributeType(attType)
        , m_PropertyOffset(poff)
        , m_DataOffset(doff)
    {
    }
};

struct SDynamicObjectTranslatorContext : public STranslatorContext
{
    typedef nvhash_map<Q3DStudio::INT32, SEffectPropertyEntry> THashToOffsetMap;
    THashToOffsetMap m_PropertyHashes;
    NVAllocatorCallback &m_Allocator;
    Qt3DSString m_Workspace;
    SDynamicObjectTranslatorContext(NVAllocatorCallback &inCallback)
        : m_PropertyHashes(inCallback, "SEffectTranslatorContext::PropertyHashes")
        , m_Allocator(inCallback)
    {
    }
    ~SDynamicObjectTranslatorContext() {}
    void AddEffectExtendedProperty(const QByteArray &baseName,
                                   const QByteArray &extension, Q3DStudio::EAttributeType inType,
                                   QByteArray &ioStringBuilder, QT3DSU32 inOffset,
                                   QT3DSU32 dataOffset)
    {
        ioStringBuilder = baseName;
        ioStringBuilder.append(extension);
        Q3DStudio::INT32 theHash = Q3DStudio::CHash::HashAttribute(ioStringBuilder.constData());
        m_PropertyHashes.insert(
            eastl::make_pair(theHash, SEffectPropertyEntry(inType, inOffset, dataOffset)));
    }
    void BuildPropertyHashes(NVConstDataRef<qt3ds::render::dynamic::SPropertyDefinition> inProperties)
    {
        if (m_PropertyHashes.size() == 0) {
            QByteArray nameBuilder;
            QByteArray baseName;
            for (QT3DSU32 idx = 0, end = inProperties.size(); idx < end; ++idx) {
                const qt3ds::render::dynamic::SPropertyDefinition &thePropDef = inProperties[idx];
                switch (thePropDef.m_DataType) {
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSF32:
                    m_PropertyHashes.insert(eastl::make_pair(
                        Q3DStudio::CHash::HashAttribute(thePropDef.m_Name.c_str()),
                        SEffectPropertyEntry(Q3DStudio::ATTRIBUTETYPE_FLOAT, idx)));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSRenderBool:
                    m_PropertyHashes.insert(
                        eastl::make_pair(Q3DStudio::CHash::HashAttribute(thePropDef.m_Name.c_str()),
                                         SEffectPropertyEntry(Q3DStudio::ATTRIBUTETYPE_BOOL, idx)));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSI32:
                    if (thePropDef.m_IsEnumProperty == false) {
                        m_PropertyHashes.insert(eastl::make_pair(
                            Q3DStudio::CHash::HashAttribute(thePropDef.m_Name.c_str()),
                            SEffectPropertyEntry(Q3DStudio::ATTRIBUTETYPE_INT32, idx)));
                    } else {
                        m_PropertyHashes.insert(eastl::make_pair(
                            Q3DStudio::CHash::HashAttribute(thePropDef.m_Name.c_str()),
                            SEffectPropertyEntry(Q3DStudio::ATTRIBUTETYPE_STRING, idx)));
                    }
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSVec2:
                    baseName = QString::fromUtf8(thePropDef.m_Name.c_str()).toUtf8();
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".x"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT, nameBuilder, idx, 0);
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".y"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT, nameBuilder, idx,
                                              sizeof(QT3DSF32));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSVec3:
                    baseName = QString::fromUtf8(thePropDef.m_Name.c_str()).toUtf8();
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".x"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 0);
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".y"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".z"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 2 * sizeof(QT3DSF32));

                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".r"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 0);
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".g"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".b"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 2 * sizeof(QT3DSF32));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::QT3DSVec4:
                    baseName = QString::fromUtf8(thePropDef.m_Name.c_str()).toUtf8();
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".x"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 0);
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".y"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".z"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 2 * sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".w"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 3 * sizeof(QT3DSF32));

                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".r"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 0);
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".g"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".b"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 2 * sizeof(QT3DSF32));
                    AddEffectExtendedProperty(baseName, QByteArrayLiteral(".a"),
                                              Q3DStudio::ATTRIBUTETYPE_FLOAT,
                                              nameBuilder, idx, 3 * sizeof(QT3DSF32));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::NVRenderTexture2DPtr:
                case qt3ds::render::NVRenderShaderDataTypes::NVRenderImage2DPtr:
                    m_PropertyHashes.insert(eastl::make_pair(
                        Q3DStudio::CHash::HashAttribute(thePropDef.m_Name.c_str()),
                        SEffectPropertyEntry(Q3DStudio::ATTRIBUTETYPE_STRING, idx)));
                    break;
                case qt3ds::render::NVRenderShaderDataTypes::NVRenderDataBufferPtr:
                    break;
                default:
                    QT3DS_ASSERT(false);
                    break;
                }
            }
        }
    }
    void ApplyChanges(SPresentation &inPresentation, IQt3DSRenderContext &inRenderContext,
                      SDynamicObject &inObject, Q3DStudio::TElement &element,
                      IDynamicObjectSystem &inSystem)
    {
        if (element.GetActive()) {
            NVConstDataRef<qt3ds::render::dynamic::SPropertyDefinition> theProperties =
                inSystem.GetProperties(inObject.m_ClassName);
            BuildPropertyHashes(theProperties);
            SDynamicObject &theItem(inObject);
            for (long idx = 0, end = element.GetAttributeCount(); idx < end; ++idx) {
                qt3ds::runtime::element::TPropertyDescAndValuePtr thePropInfo =
                    *element.GetPropertyByIndex(idx);
                THashToOffsetMap::iterator theFind =
                    m_PropertyHashes.find(thePropInfo.first.GetNameHash());
                if (theFind != m_PropertyHashes.end()) {
                    const SEffectPropertyEntry &theEntry(theFind->second);
                    const qt3ds::render::dynamic::SPropertyDefinition &theDefinition(
                        theProperties[theEntry.m_PropertyOffset]);
                    if (theEntry.m_AttributeType
                        == (Q3DStudio::EAttributeType)thePropInfo.first.m_Type) {
                        switch (theEntry.m_AttributeType) {
                        case Q3DStudio::ATTRIBUTETYPE_BOOL:
                            theItem.SetPropertyValue(theDefinition,
                                                     thePropInfo.second->m_INT32 ? true : false);
                            break;
                        case Q3DStudio::ATTRIBUTETYPE_FLOAT:
                            theItem.SetPropertyValue(theDefinition, thePropInfo.second->m_FLOAT,
                                                     theEntry.m_DataOffset);
                            break;
                        case Q3DStudio::ATTRIBUTETYPE_INT32:
                            theItem.SetPropertyValue(theDefinition,
                                                     (QT3DSI32)thePropInfo.second->m_INT32);
                            break;
                        case Q3DStudio::ATTRIBUTETYPE_STRING: {
                            CRegisteredString theStr =
                                element.GetBelongedPresentation()->GetStringTable().HandleToStr(
                                    thePropInfo.second->m_StringHandle);
                            theItem.SetPropertyValue(theDefinition, theStr.c_str(),
                                                     inPresentation.m_PresentationDirectory.c_str(),
                                                     m_Workspace, inRenderContext.GetStringTable());
                        } break;
                        default:
                            // QT3DS_ASSERT( false );
                            break;
                        }
                    } else {
                        // QT3DS_ASSERT( false );
                    }
                }
            }
            theItem.m_Flags.SetDirty(true);
        }
    }
};

struct SEffectTranslator : public Qt3DSTranslator
{
    typedef SEffect TNodeType;
    SEffectTranslator(Q3DStudio::TElement &inElement, SEffect &inRenderObject,
                      NVAllocatorCallback &inCallback)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
        m_TranslatorContext = QT3DS_NEW(inCallback, SDynamicObjectTranslatorContext)(inCallback);
    }

    void OnElementChanged(SPresentation &inPresentation, IQt3DSRenderContext &inRenderContext,
                          Q3DStudio::IPresentation &)
    {
        SRuntimePropertyParser theParser(inPresentation, inRenderContext, *m_Element);
        SEffect &theItem = *static_cast<SEffect *>(m_RenderObject);
        static_cast<SDynamicObjectTranslatorContext *>(m_TranslatorContext)
            ->ApplyChanges(inPresentation, inRenderContext, theItem, Element(),
                           inRenderContext.GetDynamicObjectSystem());
        theItem.SetActive(Element().GetActive(), inRenderContext.GetEffectSystem());
    }
};

struct SCustomMaterialTranslator : public Qt3DSTranslator
{
    typedef SCustomMaterial TNodeType;
    SCustomMaterialTranslator(Q3DStudio::TElement &inElement, SCustomMaterial &inRenderObject,
                              NVAllocatorCallback &inCallback)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
        m_TranslatorContext = QT3DS_NEW(inCallback, SDynamicObjectTranslatorContext)(inCallback);
    }

    void OnElementChanged(SPresentation &inPresentation, IQt3DSRenderContext &inRenderContext,
                          Q3DStudio::IPresentation &)
    {
        SRuntimePropertyParser theParser(inPresentation, inRenderContext, *m_Element);
        SCustomMaterial &theItem = *static_cast<SCustomMaterial *>(m_RenderObject);
        static_cast<SDynamicObjectTranslatorContext *>(m_TranslatorContext)
            ->ApplyChanges(inPresentation, inRenderContext, theItem, Element(),
                           inRenderContext.GetDynamicObjectSystem());
        bool active = m_Element->GetActive();
        if (active != theItem.m_Flags.IsActive()) {
            theItem.m_Flags.SetActive(active);
            ICustomMaterialSystem &theSystem(inRenderContext.GetCustomMaterialSystem());
            theSystem.OnMaterialActivationChange(theItem, active);
        }
    }
};

struct SRenderPluginTranslatorContext : public STranslatorContext
{
    NVAllocatorCallback &m_Allocator;
    nvhash_map<int, CRegisteredString> m_AttribHashIndexMap;
    nvvector<SRenderPropertyValueUpdate> m_PropertyUpdates;
    SRenderPluginTranslatorContext(NVAllocatorCallback &alloc)
        : m_Allocator(alloc)
        , m_AttribHashIndexMap(alloc, "SRenderPluginTranslatorContext::AttribIndexMap")
        , m_PropertyUpdates(alloc, "SRenderPluginTranslatorContext::m_PropertyUpdates")
    {
    }
    void ReverseMap(CRegisteredString str)
    {
        m_AttribHashIndexMap.insert(
            eastl::make_pair(Q3DStudio::CHash::HashAttribute(str.c_str()), str));
    }
};

struct SRenderPluginTranslator : public Qt3DSTranslator
{
    typedef SRenderPlugin TNodeType;
    SRenderPluginTranslator(Q3DStudio::TElement &inElement, SRenderPlugin &inRenderObject,
                            NVAllocatorCallback &inCallback)
        : Qt3DSTranslator(inElement, inRenderObject)
    {
        m_TranslatorContext = QT3DS_NEW(inCallback, SRenderPluginTranslatorContext)(inCallback);
    }

    void OnElementChanged(SPresentation & /*inPresentation*/, IQt3DSRenderContext &inRenderContext,
                          Q3DStudio::IPresentation &)
    {
        SRenderPlugin &theItem = *static_cast<SRenderPlugin *>(m_RenderObject);
        theItem.m_Flags.SetActive(Element().GetActive());
        IRenderPluginInstance *theInstance =
            inRenderContext.GetRenderPluginManager().GetOrCreateRenderPluginInstance(
                theItem.m_PluginPath, &theItem);
        if (theInstance != NULL) {
            IRenderPluginClass &theClass(theInstance->GetPluginClass());
            SRenderPluginTranslatorContext &theTransContext =
                static_cast<SRenderPluginTranslatorContext &>(*m_TranslatorContext);
            if (theTransContext.m_AttribHashIndexMap.empty()) {
                NVConstDataRef<SRenderPluginPropertyDeclaration> theProperties(
                    theClass.GetRegisteredProperties());
                for (QT3DSU32 idx = 0, end = theProperties.size(); idx < end; ++idx) {
                    const SRenderPluginPropertyDeclaration &theDec(theProperties[idx]);
                    switch (theDec.m_Type) {
                    case SRenderPluginPropertyTypes::Boolean:
                        theTransContext.ReverseMap(theDec.m_Name);
                        break;
                    case SRenderPluginPropertyTypes::Float:
                        theTransContext.ReverseMap(theDec.m_Name);
                        break;
                    case SRenderPluginPropertyTypes::Long:
                        theTransContext.ReverseMap(theDec.m_Name);
                        break;
                    case SRenderPluginPropertyTypes::String:
                        theTransContext.ReverseMap(theDec.m_Name);
                        break;
                    case SRenderPluginPropertyTypes::Vector2:
                        theTransContext.ReverseMap(
                            theClass.GetPropertyValueInfo(theDec.m_StartOffset).first);
                        theTransContext.ReverseMap(
                            theClass.GetPropertyValueInfo(theDec.m_StartOffset + 1).first);
                        break;
                    case SRenderPluginPropertyTypes::Vector3:
                    case SRenderPluginPropertyTypes::Color:
                        theTransContext.ReverseMap(
                            theClass.GetPropertyValueInfo(theDec.m_StartOffset).first);
                        theTransContext.ReverseMap(
                            theClass.GetPropertyValueInfo(theDec.m_StartOffset + 1).first);
                        theTransContext.ReverseMap(
                            theClass.GetPropertyValueInfo(theDec.m_StartOffset + 2).first);
                        break;
                    default:
                        // QT3DS_ASSERT( false );
                        break;
                    }
                }
            } // ok, now we have an efficient mapping from attribute to plugin value name.
            theTransContext.m_PropertyUpdates.clear();
            for (long idx = 0, end = Element().GetAttributeCount(); idx < end; ++idx) {
                qt3ds::runtime::element::TPropertyDescAndValuePtr thePropInfo =
                    *Element().GetPropertyByIndex(idx);
                nvhash_map<int, CRegisteredString>::iterator theFind =
                    theTransContext.m_AttribHashIndexMap.find(thePropInfo.first.GetNameHash());
                if (theFind != theTransContext.m_AttribHashIndexMap.end()) {
                    CRegisteredString thePropName(theFind->second);
                    Q3DStudio::EAttributeType theType =
                        (Q3DStudio::EAttributeType)thePropInfo.first.m_Type;
                    switch (theType) {
                    case Q3DStudio::ATTRIBUTETYPE_BOOL:
                        theTransContext.m_PropertyUpdates.push_back(SRenderPropertyValueUpdate(
                            thePropName, thePropInfo.second->m_INT32 ? true : false));
                        break;
                    case Q3DStudio::ATTRIBUTETYPE_FLOAT:
                        theTransContext.m_PropertyUpdates.push_back(
                            SRenderPropertyValueUpdate(thePropName, thePropInfo.second->m_FLOAT));
                        break;
                    case Q3DStudio::ATTRIBUTETYPE_INT32:
                        theTransContext.m_PropertyUpdates.push_back(SRenderPropertyValueUpdate(
                            thePropName, (QT3DSI32)thePropInfo.second->m_INT32));
                        break;
                    case Q3DStudio::ATTRIBUTETYPE_STRING: {
                        CRegisteredString theStr = inRenderContext.GetStringTable().HandleToStr(
                            thePropInfo.second->m_StringHandle);
                        theTransContext.m_PropertyUpdates.push_back(
                            SRenderPropertyValueUpdate(thePropName, theStr));
                    } break;
                    default:
                        // QT3DS_ASSERT( false );
                        break;
                    }
                }
            }
            if (theTransContext.m_PropertyUpdates.empty() == false) {
                theInstance->Update(toConstDataRef(theTransContext.m_PropertyUpdates.data(),
                                                   theTransContext.m_PropertyUpdates.size()));
            }
        }
    }
};
}

Qt3DSTranslator::Qt3DSTranslator(Q3DStudio::TElement &inElement, SGraphObject &inRenderObject)
    : m_DirtyIndex(QT3DS_MAX_U32)
    , m_Element(&inElement)
    , m_RenderObject(&inRenderObject)
    , m_TranslatorContext(NULL)
{
    Element().SetAssociation(reinterpret_cast<void *>(this));
    inRenderObject.m_UserData = STaggedPointer(this);
}

void Qt3DSTranslator::Save(SWriteBuffer &inWriteBuffer, QT3DSU32 inGraphObjectOffset)
{
    // We have to start on pointer aligned boundaries.
    QT3DS_ASSERT(inWriteBuffer.size() % 4 == 0);
    QT3DSU32 theOffset = inWriteBuffer.size();
    inWriteBuffer.write(*this);
    Qt3DSTranslator *theNewTranslator =
        reinterpret_cast<Qt3DSTranslator *>(inWriteBuffer.begin() + theOffset);
    theNewTranslator->m_DirtyIndex = QT3DS_MAX_U32;
    if (theNewTranslator->m_Element)
        theNewTranslator->m_Element = m_Element->GetBelongedPresentation()
                                          ->GetApplication()
                                          .GetElementAllocator()
                                          .GetRemappedElementAddress(m_Element);
    size_t *graphObjPtr = reinterpret_cast<size_t *>(&theNewTranslator->m_RenderObject);
    *graphObjPtr = inGraphObjectOffset;
}

Qt3DSTranslator *Qt3DSTranslator::GetTranslatorFromGraphNode(SGraphObject &inObject)
{
    return inObject.m_UserData.DynamicCast<Qt3DSTranslator>();
}

namespace {
struct SPresentationTranslator;
struct SEffectTranslator;
template <typename TTranslatorType>
struct STranslatorCreator
{
    static TTranslatorType *Create(Q3DStudio::TElement &inElement, SGraphObject &inObject,
                                   NVAllocatorCallback &inAllocator)
    {
        typedef typename TTranslatorType::TNodeType TNodeType;
        // This assert needs to be here because we serialize all translators generically without
        // regard for type.
        StaticAssert<sizeof(TTranslatorType) == sizeof(Qt3DSTranslator)>::valid_expression();
        return QT3DS_NEW(inAllocator, TTranslatorType)(inElement, static_cast<TNodeType &>(inObject));
    }
    static void InitializeTranslator(Qt3DSTranslator &inTranslator, NVAllocatorCallback &)
    {
        typedef typename TTranslatorType::TNodeType TNodeType;
        // Initialize the vtable.
        new (&inTranslator) TTranslatorType(inTranslator.Element(),
                                            static_cast<TNodeType &>(inTranslator.RenderObject()));
    }

    static void OnElementChanged(Qt3DSTranslator &inTranslator, SPresentation &inPresentation,
                                 IQt3DSRenderContext &inRenderContext,
                                 Q3DStudio::IPresentation &inStudioPresentation)
    {
        TTranslatorType &theTranslator(static_cast<TTranslatorType &>(inTranslator));
        SRuntimePropertyParser theParser(inPresentation, inRenderContext, *theTranslator.m_Element);
        bool isMaterial = QString(theTranslator.Element().GetTypeDescription().m_TypeName.c_str())
                .contains(QLatin1String("Material"));
        if (theTranslator.Element().GetActive() || isMaterial) {
            // Don't push properties from inactive elements.
            // Exceptions to this rule are Materials since materials that reference them need
            // the values even when the original material is inactive
            for (long idx = 0, end = theTranslator.Element().GetAttributeCount(); idx < end;
                 ++idx) {
                qt3ds::runtime::element::TPropertyDescAndValuePtr thePropInfo =
                    *theTranslator.Element().GetPropertyByIndex(idx);
                theParser.Setup(thePropInfo.first.GetNameHash(), *thePropInfo.second,
                                (Q3DStudio::EAttributeType)thePropInfo.first.m_Type);
                // right now, this is the best we can do because the attribute's dirty system
                // is all jacked up.
                theTranslator.OnSpecificPropertyChange(theParser);
            }
            // same for dynamic properties
            for (long idx = 0, end = theTranslator.Element().GetDynamicAttributeCount(); idx < end;
                 ++idx) {
                qt3ds::runtime::element::TPropertyDescAndValuePtr thePropInfo =
                    *theTranslator.Element().GetDynamicPropertyByIndex(idx);
                theParser.Setup(thePropInfo.first.GetNameHash(), *thePropInfo.second,
                                (Q3DStudio::EAttributeType)thePropInfo.first.m_Type);
                // right now, this is the best we can do because the attribute's dirty system
                // is all jacked up.
                theTranslator.OnSpecificPropertyChange(theParser);
            }
            // Set appropriate dirty flags
        }
        theTranslator.PostPropertyChanged(theParser, inStudioPresentation);
    }
};

template <>
struct STranslatorCreator<SPresentationTranslator>
{
    static Qt3DSTranslator *Create(Q3DStudio::TElement &, SGraphObject &, NVAllocatorCallback &)
    {
        return NULL;
    }
    static void InitializeTranslator(Qt3DSTranslator &, NVAllocatorCallback &) {}
    static void OnElementChanged(Qt3DSTranslator & /*inTranslator*/,
                                 SPresentation & /*inPresentation*/
                                 ,
                                 IQt3DSRenderContext & /*inRenderContext*/,
                                 Q3DStudio::IPresentation & /*inStudioPresentation*/)
    {
        QT3DS_ASSERT(false);
    }
};

template <>
struct STranslatorCreator<SEffectTranslator>
{
    static SEffectTranslator *Create(Q3DStudio::TElement &inElement, SGraphObject &inObject,
                                     NVAllocatorCallback &inAllocator)
    {
        typedef SEffectTranslator::TNodeType TNodeType;
        // This assert needs to be here because we serialize all translators generically without
        // regard for type.
        StaticAssert<sizeof(SEffectTranslator) == sizeof(Qt3DSTranslator)>::valid_expression();
        return QT3DS_NEW(inAllocator, SEffectTranslator)(inElement, static_cast<TNodeType &>(inObject),
                                                      inAllocator);
    }

    static void InitializeTranslator(Qt3DSTranslator &inTranslator, NVAllocatorCallback &inAllocator)
    {
        typedef SEffectTranslator::TNodeType TNodeType;
        // Initialize the vtable.
        new (&inTranslator)
            SEffectTranslator(inTranslator.Element(),
                              static_cast<TNodeType &>(inTranslator.RenderObject()), inAllocator);
    }
    static void OnElementChanged(Qt3DSTranslator &inTranslator, SPresentation &inPresentation,
                                 IQt3DSRenderContext &inRenderContext,
                                 Q3DStudio::IPresentation &inStudioPresentation)
    {
        static_cast<SEffectTranslator &>(inTranslator)
            .OnElementChanged(inPresentation, inRenderContext, inStudioPresentation);
    }
};

template <>
struct STranslatorCreator<SCustomMaterialTranslator>
{
    static SCustomMaterialTranslator *Create(Q3DStudio::TElement &inElement, SGraphObject &inObject,
                                             NVAllocatorCallback &inAllocator)
    {
        typedef SCustomMaterialTranslator::TNodeType TNodeType;
        // This assert needs to be here because we serialize all translators generically without
        // regard for type.
        StaticAssert<sizeof(SCustomMaterialTranslator)
                     == sizeof(Qt3DSTranslator)>::valid_expression();
        return QT3DS_NEW(inAllocator, SCustomMaterialTranslator)(
            inElement, static_cast<TNodeType &>(inObject), inAllocator);
    }

    static void InitializeTranslator(Qt3DSTranslator &inTranslator, NVAllocatorCallback &inAllocator)
    {
        typedef SCustomMaterialTranslator::TNodeType TNodeType;
        // Initialize the vtable.
        new (&inTranslator) SCustomMaterialTranslator(
            inTranslator.Element(), static_cast<TNodeType &>(inTranslator.RenderObject()),
            inAllocator);
    }

    static void OnElementChanged(Qt3DSTranslator &inTranslator, SPresentation &inPresentation,
                                 IQt3DSRenderContext &inRenderContext,
                                 Q3DStudio::IPresentation &inStudioPresentation)
    {
        static_cast<SCustomMaterialTranslator &>(inTranslator)
            .OnElementChanged(inPresentation, inRenderContext, inStudioPresentation);
    }
};

template <>
struct STranslatorCreator<SRenderPluginTranslator>
{
    static SRenderPluginTranslator *Create(Q3DStudio::TElement &inElement, SGraphObject &inObject,
                                           NVAllocatorCallback &inAllocator)
    {
        typedef SRenderPluginTranslator::TNodeType TNodeType;
        // This assert needs to be here because we serialize all translators generically without
        // regard for type.
        StaticAssert<sizeof(SRenderPluginTranslator) == sizeof(Qt3DSTranslator)>::valid_expression();
        return QT3DS_NEW(inAllocator, SRenderPluginTranslator)(
            inElement, static_cast<TNodeType &>(inObject), inAllocator);
    }

    static void InitializeTranslator(Qt3DSTranslator &inTranslator, NVAllocatorCallback &inAllocator)
    {
        typedef SRenderPluginTranslator::TNodeType TNodeType;
        // Initialize the vtable.
        new (&inTranslator) SRenderPluginTranslator(
            inTranslator.Element(), static_cast<TNodeType &>(inTranslator.RenderObject()),
            inAllocator);
    }
    static void OnElementChanged(Qt3DSTranslator &inTranslator, SPresentation &inPresentation,
                                 IQt3DSRenderContext &inRenderContext,
                                 Q3DStudio::IPresentation &inStudioPresentation)
    {
        static_cast<SRenderPluginTranslator &>(inTranslator)
            .OnElementChanged(inPresentation, inRenderContext, inStudioPresentation);
    }
};
}
Qt3DSTranslator *Qt3DSTranslator::CreateTranslatorForElement(Q3DStudio::TElement &inElement,
                                                           SGraphObject &inObject,
                                                           NVAllocatorCallback &inAlloc)
{
    Qt3DSTranslator *theTranslator = NULL;
    switch (inObject.m_Type) {
#define QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE(type)                                                   \
    case GraphObjectTypes::type:                                                                   \
        theTranslator =                                                                            \
            STranslatorCreator<S##type##Translator>::Create(inElement, inObject, inAlloc);         \
        break;
        QT3DS_RENDER_ITERATE_GRAPH_OBJECT_TYPES
#undef QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE
    default:
        QT3DS_ASSERT(false);
        break;
    }
    return theTranslator;
}

void Qt3DSTranslator::OnElementChanged(SPresentation &inPresentation,
                                      IQt3DSRenderContext &inRenderContext,
                                      Q3DStudio::IPresentation &inStudioPresentation)
{
    switch (m_RenderObject->m_Type) {
#define QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE(type)                                                   \
    case GraphObjectTypes::type:                                                                   \
        STranslatorCreator<S##type##Translator>::OnElementChanged(                                 \
            *this, inPresentation, inRenderContext, inStudioPresentation);                         \
        break;
        QT3DS_RENDER_ITERATE_GRAPH_OBJECT_TYPES
#undef QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE
    default:
        QT3DS_ASSERT(false);
        break;
    }
}

Qt3DSTranslator *Qt3DSTranslator::LoadTranslator(SDataReader &inReader, size_t inElemOffset,
                                               NVDataRef<QT3DSU8> inSGSection,
                                               NVAllocatorCallback &inAllocator)
{
    // Reader points to a new translator but we don't know what type
    QT3DSU8 *theTranslatorStart = inReader.m_CurrentPtr;
    // Make sure things are aligned
    (void)theTranslatorStart;
    QT3DS_ASSERT((size_t)theTranslatorStart % 4 == 0);
    Qt3DSTranslator *theTranslator = inReader.Load<Qt3DSTranslator>();
    if (theTranslator) {
        size_t *elemPtr = reinterpret_cast<size_t *>(&theTranslator->m_Element);
        *elemPtr += inElemOffset;
        size_t *graphObjPtr = reinterpret_cast<size_t *>(&theTranslator->m_RenderObject);
        size_t sgSectionStart = reinterpret_cast<size_t>(inSGSection.begin());
        *graphObjPtr += sgSectionStart;
        // Call actual constructor to initialize vtable.
        switch (theTranslator->RenderObject().m_Type) {
#define QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE(type)                                                   \
    case GraphObjectTypes::type:                                                                   \
        STranslatorCreator<S##type##Translator>::InitializeTranslator(*theTranslator,              \
                                                                      inAllocator);                \
        break;
            QT3DS_RENDER_ITERATE_GRAPH_OBJECT_TYPES
#undef QT3DS_RENDER_HANDL_GRAPH_OBJECT_TYPE
        default:
            QT3DS_ASSERT(false);
            break;
        }
    }
    return theTranslator;
}
Q3DStudio::IPresentation *
Qt3DSTranslator::GetPresentationFromPresentation(SPresentation &inPresentation)
{
    return inPresentation.m_UserData.DynamicCast<Q3DStudio::IPresentation>();
}

void Qt3DSTranslator::InitializePointerTags(IStringTable &)
{
    g_TranslatorTag = 0x0044FEED;
    g_PresentationTag = 0x0022ABBA;
}

void Qt3DSTranslator::AssignUserData(Q3DStudio::IPresentation &inPresentation,
                                    SPresentation &inGraphPresentation)
{
    inGraphPresentation.m_UserData = STaggedPointer(&inPresentation);
}