My favorites | Sign in
Project Home Source
Checkout   Browse   Changes  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227

#include "modelviewer.h"
#include "globalvars.h"

// default colour values
const static float def_ambience[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const static float def_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const static float def_emission[4] = {0.0f, 0.0f, 0.0f, 1.0f};
const static float def_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};

//test comment ~ZT

// Class event handler/importer
IMPLEMENT_CLASS(ModelViewer, wxFrame)

BEGIN_EVENT_TABLE(ModelViewer, wxFrame)
EVT_CLOSE(ModelViewer::OnClose)
//EVT_SIZE(ModelViewer::OnSize)

// File menu
EVT_MENU(ID_VIEW_NPC, ModelViewer::OnCharToggle)
EVT_MENU(ID_VIEW_ITEM, ModelViewer::OnCharToggle)
EVT_MENU(ID_FILE_SCREENSHOT, ModelViewer::OnSave)
EVT_MENU(ID_FILE_SCREENSHOTCONFIG, ModelViewer::OnSave)
EVT_MENU(ID_FILE_EXPORTGIF, ModelViewer::OnSave)
EVT_MENU(ID_FILE_EXPORTAVI, ModelViewer::OnSave)
// --
//EVT_MENU(ID_FILE_TEXIMPORT, ModelViewer::OnTex)
EVT_MENU(ID_FILE_TEXEXPORT, ModelViewer::OnExport)
EVT_MENU(ID_FILE_MODELEXPORT_MENU, ModelViewer::OnExport)
EVT_MENU(ID_FILE_MODEL_INFO, ModelViewer::OnExportOther)
EVT_MENU(ID_FILE_DISCOVERY_ITEM, ModelViewer::OnExportOther)
EVT_MENU(ID_FILE_DISCOVERY_NPC, ModelViewer::OnExportOther)
//--
// Export Menu
// To add your new exporter, simply copy the bottom line, and add your unique ID (specified in enums.h) as seen below.
// Make sure to use this ID for your export command in the ModelViewer::OnExport function!
EVT_MENU(ID_MODELEXPORT_OPTIONS, ModelViewer::OnToggleDock)
EVT_MENU(ID_MODELEXPORT_INIT, ModelViewer::OnToggleCommand)
EVT_MENU(ID_MODELEXPORT_LWO, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_LWO2, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_OBJ, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_COLLADA, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_MS3D, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_3DS, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_X3D, ModelViewer::OnExport)
EVT_MENU(ID_MODELEXPORT_XHTML, ModelViewer::OnExport)
// --
EVT_MENU(ID_FILE_RESETLAYOUT, ModelViewer::OnToggleCommand)
// --
EVT_MENU(ID_FILE_EXIT, ModelViewer::OnExit)

// view menu
EVT_MENU(ID_SHOW_FILE_LIST, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_ANIM, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_CHAR, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_LIGHT, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_MODEL, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_MODELBANK, ModelViewer::OnToggleDock)
EVT_MENU(ID_SHOW_MODELOPENED, ModelViewer::OnToggleDock)
// --
EVT_MENU(ID_SHOW_MASK, ModelViewer::OnToggleCommand)
//EVT_MENU(ID_SHOW_WIREFRAME, ModelViewer::OnToggleCommand)
//EVT_MENU(ID_SHOW_BONES, ModelViewer::OnToggleCommand)
EVT_MENU(ID_SHOW_BOUNDS, ModelViewer::OnToggleCommand)
//EVT_MENU(ID_SHOW_PARTICLES, ModelViewer::OnToggleCommand)

EVT_MENU(ID_BACKGROUND, ModelViewer::OnBackground)
EVT_MENU(ID_BG_COLOR, ModelViewer::OnSetColor)
EVT_MENU(ID_SKYBOX, ModelViewer::OnBackground)
EVT_MENU(ID_SHOW_GRID, ModelViewer::OnToggleCommand)

EVT_MENU(ID_USE_CAMERA, ModelViewer::OnToggleCommand)

// Cam
EVT_MENU(ID_CAM_FRONT, ModelViewer::OnCamMenu)
EVT_MENU(ID_CAM_SIDE, ModelViewer::OnCamMenu)
EVT_MENU(ID_CAM_BACK, ModelViewer::OnCamMenu)
EVT_MENU(ID_CAM_ISO, ModelViewer::OnCamMenu)

EVT_MENU(ID_CANVAS120, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS512, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS640, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS800, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS1024, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS1152, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS1280, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVAS1600, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVASW720, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVASW1080, ModelViewer::OnCanvasSize)
EVT_MENU(ID_CANVASW1200, ModelViewer::OnCanvasSize)

// hidden hotkeys for zooming
EVT_MENU(ID_ZOOM_IN, ModelViewer::OnToggleCommand)
EVT_MENU(ID_ZOOM_OUT, ModelViewer::OnToggleCommand)

// Light Menu
EVT_MENU(ID_LT_SAVE, ModelViewer::OnLightMenu)
EVT_MENU(ID_LT_LOAD, ModelViewer::OnLightMenu)
//EVT_MENU(ID_LT_COLOR, ModelViewer::OnSetColor)
EVT_MENU(ID_LT_TRUE, ModelViewer::OnLightMenu)
EVT_MENU(ID_LT_AMBIENT, ModelViewer::OnLightMenu)
EVT_MENU(ID_LT_DIRECTIONAL, ModelViewer::OnLightMenu)
EVT_MENU(ID_LT_MODEL, ModelViewer::OnLightMenu)
EVT_MENU(ID_LT_DIRECTION, ModelViewer::OnLightMenu)

// Effects
EVT_MENU(ID_ENCHANTS, ModelViewer::OnEffects)
EVT_MENU(ID_SPELLS, ModelViewer::OnEffects)
EVT_MENU(ID_EQCREATURE_R, ModelViewer::OnEffects)
EVT_MENU(ID_EQCREATURE_L, ModelViewer::OnEffects)
EVT_MENU(ID_SHADER_DEATH, ModelViewer::OnEffects)
EVT_MENU(ID_TEST, ModelViewer::OnTest)

// Options
EVT_MENU(ID_SAVE_CHAR, ModelViewer::OnToggleCommand)
EVT_MENU(ID_LOAD_CHAR, ModelViewer::OnToggleCommand)
EVT_MENU(ID_IMPORT_CHAR, ModelViewer::OnToggleCommand)

#ifndef WotLK
EVT_MENU(ID_USE_NPCSKINS, ModelViewer::OnCharToggle)
#endif
EVT_MENU(ID_DEFAULT_DOODADS, ModelViewer::OnToggleCommand)
EVT_MENU(ID_USE_ANTIALIAS, ModelViewer::OnToggleCommand)
EVT_MENU(ID_USE_HWACC, ModelViewer::OnToggleCommand)
EVT_MENU(ID_USE_ENVMAP, ModelViewer::OnToggleCommand)
EVT_MENU(ID_SHOW_SETTINGS, ModelViewer::OnToggleDock)

// char controls:
EVT_MENU(ID_SAVE_EQUIPMENT, ModelViewer::OnSetEquipment)
EVT_MENU(ID_LOAD_EQUIPMENT, ModelViewer::OnSetEquipment)
EVT_MENU(ID_CLEAR_EQUIPMENT, ModelViewer::OnSetEquipment)

EVT_MENU(ID_LOAD_SET, ModelViewer::OnSetEquipment)
EVT_MENU(ID_LOAD_START, ModelViewer::OnSetEquipment)
EVT_MENU(ID_LOAD_NPC_START, ModelViewer::OnSetEquipment)

EVT_MENU(ID_SHOW_UNDERWEAR, ModelViewer::OnCharToggle)
EVT_MENU(ID_SHOW_EARS, ModelViewer::OnCharToggle)
EVT_MENU(ID_SHOW_HAIR, ModelViewer::OnCharToggle)
EVT_MENU(ID_SHOW_FACIALHAIR, ModelViewer::OnCharToggle)
EVT_MENU(ID_SHOW_FEET, ModelViewer::OnCharToggle)
EVT_MENU(ID_SHEATHE, ModelViewer::OnCharToggle)

EVT_MENU(ID_MOUNT_CHARACTER, ModelViewer::OnMount)
EVT_MENU(ID_CHAR_RANDOMISE, ModelViewer::OnSetEquipment)

// About menu
EVT_MENU(ID_CHECKFORUPDATE, ModelViewer::OnCheckForUpdate)
EVT_MENU(ID_LANGUAGE, ModelViewer::OnLanguage)
EVT_MENU(ID_HELP, ModelViewer::OnAbout)
EVT_MENU(ID_ABOUT, ModelViewer::OnAbout)

// Hidden menu items
// Temporary saves
EVT_MENU(ID_SAVE_TEMP1, ModelViewer::OnToggleCommand)
EVT_MENU(ID_SAVE_TEMP2, ModelViewer::OnToggleCommand)
EVT_MENU(ID_SAVE_TEMP3, ModelViewer::OnToggleCommand)
EVT_MENU(ID_SAVE_TEMP4, ModelViewer::OnToggleCommand)

// Temp loads
EVT_MENU(ID_LOAD_TEMP1, ModelViewer::OnToggleCommand)
EVT_MENU(ID_LOAD_TEMP2, ModelViewer::OnToggleCommand)
EVT_MENU(ID_LOAD_TEMP3, ModelViewer::OnToggleCommand)
EVT_MENU(ID_LOAD_TEMP4, ModelViewer::OnToggleCommand)

END_EVENT_TABLE()


ModelViewer::ModelViewer()
{
// our main class objects
animControl = NULL;
canvas = NULL;
charControl = NULL;
enchants = NULL;
lightControl = NULL;
modelControl = NULL;
arrowControl = NULL;
imageControl = NULL;
settingsControl = NULL;
modelbankControl = NULL;
modelOpened = NULL;
animExporter = NULL;
fileControl = NULL;
exportOptionsControl = NULL;

//wxWidget objects
menuBar = NULL;
charMenu = NULL;
viewMenu = NULL;
optMenu = NULL;
lightMenu = NULL;
exportMenu = NULL;

isModel = false;
isWMO = false;
isChar = false;

//wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU
// create our main frame
if (Create(NULL, wxID_ANY, wxString(APP_TITLE _T(" ") APP_VERSION _T(" ") APP_PLATFORM), wxDefaultPosition, wxSize(1024, 768), wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN, _T("ModelViewerFrame"))) {
SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
SetBackgroundStyle(wxBG_STYLE_CUSTOM);

InitObjects(); // create our canvas, anim control, character control, etc

// Show our window
Show(true);
// Display the window
Centre();

// ------
// Initialise our main window.
// Load session settings
LoadSession();

// create our menu objects
InitMenu();

// GUI and Canvas Stuff
InitDocking();

// Are these really needed?
interfaceManager.Update();
Refresh();
Update();

// load our World of Warcraft mpq archives
bool initbool = Init();
if (initbool == false){
wxString info = _T("Fatal Error: WoW Model Viewer does not support your version of WoW.\nPlease update your World of Warcraft client!");
wxLogMessage(info);
wxMessageDialog *dial = new wxMessageDialog(NULL, info, wxT("Version Mismatch"), wxOK | wxICON_ERROR);
dial->ShowModal();
Close(true);
return;
}

InitDatabase();
// --

// Error check
if (!initDB) {
wxMessageBox(_T("Some DBC files could not be loaded. These files are vital to being able to render models correctly.\nPlease make sure you are loading the 'Locale-xxxx.MPQ' file.\nFile list has been disabled until you are able to correct this problem."), _("DBC Error"));
fileControl->Disable();
}

} else {
wxLogMessage(_T("Critical Error: Unable to create the main window for the application."));
Close(true);
}
}

void ModelViewer::InitMenu()
{
wxLogMessage(_T("Initiating File Menu.."));

// MENU
fileMenu = new wxMenu;
fileMenu->Append(ID_FILE_SCREENSHOT, _("Save Screenshot\tF12"));
fileMenu->Append(ID_FILE_SCREENSHOTCONFIG, _("Save Sized Screenshot\tCTRL+S"));
fileMenu->Append(ID_FILE_EXPORTGIF, _("GIF/Sequence Export"));
fileMenu->Append(ID_FILE_EXPORTAVI, _("Export AVI"));
fileMenu->AppendSeparator();
/*
fileMenu->Append(ID_FILE_TEXIMPORT, _("Import Texture"));
fileMenu->Enable(ID_FILE_TEXIMPORT, false);
fileMenu->Append(ID_FILE_TEXEXPORT, _("Export Texture"));
fileMenu->Enable(ID_FILE_TEXEXPORT, false);
*/
fileMenu->Append(ID_SHOW_MODELOPENED, _("Export Textures..."));

// --== New Model Export Menu! ==--
//To add your exporter, simply copy the bottom line below, and change the nessicary information.

exportMenu = new wxMenu;
exportMenu->AppendCheckItem(ID_MODELEXPORT_INIT, _("Initial Pose Only"));
exportMenu->Check(ID_MODELEXPORT_INIT, modelExportInitOnly);
exportMenu->AppendSeparator();
exportMenu->Append(ID_MODELEXPORT_OPTIONS, _("Export Options..."));
exportMenu->AppendSeparator();
#ifdef _DEBUG
exportMenu->Append(ID_MODELEXPORT_LWO2, _("Experimental Lightwave..."));
#endif
exportMenu->Append(ID_MODELEXPORT_LWO, _("Lightwave..."));
exportMenu->Append(ID_MODELEXPORT_OBJ, _("Wavefront OBJ..."));
exportMenu->Append(ID_MODELEXPORT_COLLADA, _("Collada..."));
exportMenu->Append(ID_MODELEXPORT_MS3D, _("Milkshape..."));
exportMenu->Append(ID_MODELEXPORT_3DS, _("3DS..."));
exportMenu->Append(ID_MODELEXPORT_X3D, _("X3D..."));
exportMenu->Append(ID_MODELEXPORT_XHTML, _("X3D in XHTML..."));

// -= Enable/Disable Model Exporters =-
// If you don't support WMOs or M2 files yet, you can disable export for that in filecontrol.cpp,
// at the bottom of the FileControl::OnTreeSelect function.
exportMenu->Enable(ID_MODELEXPORT_COLLADA, false);

// -= Create Model Export Menu =-
fileMenu->Append(ID_FILE_MODELEXPORT_MENU, _("Export Model"), exportMenu);

// --== Continue regular menu ==--
fileMenu->AppendSeparator();
fileMenu->Append(ID_FILE_DISCOVERY_ITEM, _("Discovery Item"));
if (wxFileExists(_T("discoveryitems.csv")))
fileMenu->Enable(ID_FILE_DISCOVERY_ITEM, false);
fileMenu->Append(ID_FILE_DISCOVERY_NPC, _("Discovery NPC"));
fileMenu->AppendSeparator();
fileMenu->Append(ID_FILE_MODEL_INFO, _("Export ModelInfo.xml"));

fileMenu->AppendSeparator();
fileMenu->Append(ID_FILE_RESETLAYOUT, _("Reset Layout"));
fileMenu->AppendSeparator();
fileMenu->Append(ID_FILE_EXIT, _("E&xit\tCTRL+X"));

viewMenu = new wxMenu;
viewMenu->Append(ID_VIEW_NPC, _("View NPC"));
viewMenu->Append(ID_VIEW_ITEM, _("View Item"));
viewMenu->AppendSeparator();
viewMenu->Append(ID_SHOW_FILE_LIST, _("Show file list"));
viewMenu->Append(ID_SHOW_ANIM, _("Show animaton control"));
viewMenu->Append(ID_SHOW_CHAR, _("Show character control"));
viewMenu->Append(ID_SHOW_LIGHT, _("Show light control"));
viewMenu->Append(ID_SHOW_MODEL, _("Show model control"));
viewMenu->Append(ID_SHOW_MODELBANK, _("Show model bank"));
viewMenu->AppendSeparator();
if (canvas) {
viewMenu->Append(ID_BG_COLOR, _("Background Color..."));
viewMenu->AppendCheckItem(ID_BACKGROUND, _("Load Background\tCTRL+L"));
viewMenu->Check(ID_BACKGROUND, canvas->drawBackground);
viewMenu->AppendCheckItem(ID_SKYBOX, _("Skybox"));
viewMenu->Check(ID_SKYBOX, canvas->drawSky);
viewMenu->AppendCheckItem(ID_SHOW_GRID, _("Show Grid"));
viewMenu->Check(ID_SHOW_GRID, canvas->drawGrid);

viewMenu->AppendCheckItem(ID_SHOW_MASK, _("Show Mask"));
viewMenu->Check(ID_SHOW_MASK, false);

viewMenu->AppendSeparator();
}



try {

// Camera Menu
wxMenu *camMenu = new wxMenu;
camMenu->AppendCheckItem(ID_USE_CAMERA, _("Use model camera"));
camMenu->AppendSeparator();
camMenu->Append(ID_CAM_FRONT, _("Front"));
camMenu->Append(ID_CAM_BACK, _("Back"));
camMenu->Append(ID_CAM_SIDE, _("Side"));
camMenu->Append(ID_CAM_ISO, _("Perspective"));

viewMenu->Append(ID_CAMERA, _("Camera"), camMenu);
viewMenu->AppendSeparator();

wxMenu *setSize = new wxMenu;
setSize->AppendRadioItem(ID_CANVAS120, _T("120 x 120"));
setSize->AppendRadioItem(ID_CANVAS512, _T("512 x 512"));
setSize->AppendRadioItem(ID_CANVAS640, _T("640 x 480"));
setSize->AppendRadioItem(ID_CANVAS800, _T("800 x 600"));
setSize->AppendRadioItem(ID_CANVAS1024, _T("1024 x 768"));
setSize->AppendRadioItem(ID_CANVAS1152, _T("1152 x 864"));
setSize->AppendRadioItem(ID_CANVAS1280, _T("1280 x 768"));
setSize->AppendRadioItem(ID_CANVAS1600, _T("1600 x 1200"));
setSize->AppendRadioItem(ID_CANVASW720, _T("1280 x 720"));
setSize->AppendRadioItem(ID_CANVASW1080, _T("1920 x 1080"));
setSize->AppendRadioItem(ID_CANVASW1200, _T("1920 x 1200"));

viewMenu->Append(ID_CANVASSIZE, _("Set Canvas Size"), setSize);

//lightMenu->Append(ID_LT_COLOR, _("Lighting Color..."));

lightMenu = new wxMenu;
lightMenu->Append(ID_LT_SAVE, _("Save Lighting"));
lightMenu->Append(ID_LT_LOAD, _("Load Lighting"));
lightMenu->AppendSeparator();
lightMenu->AppendCheckItem(ID_LT_DIRECTION, _("Render Light Objects"));
lightMenu->AppendSeparator();
lightMenu->AppendCheckItem(ID_LT_TRUE, _("Use true lighting"));
lightMenu->Check(ID_LT_TRUE, false);
lightMenu->AppendRadioItem(ID_LT_DIRECTIONAL, _("Use dynamic light"));
lightMenu->Check(ID_LT_DIRECTIONAL, true);
lightMenu->AppendRadioItem(ID_LT_AMBIENT, _("Use ambient light"));
lightMenu->AppendRadioItem(ID_LT_MODEL, _("Model lights only"));

charMenu = new wxMenu;
charMenu->Append(ID_LOAD_CHAR, _("Load Character\tF8"));
charMenu->Append(ID_IMPORT_CHAR, _("Import Armory Character"));
charMenu->Append(ID_SAVE_CHAR, _("Save Character\tF7"));
charMenu->AppendSeparator();
charMenu->AppendCheckItem(ID_SHOW_UNDERWEAR, _("Show Underwear"));
charMenu->Check(ID_SHOW_UNDERWEAR, true);
charMenu->AppendCheckItem(ID_SHOW_EARS, _("Show Ears\tCTRL+E"));
charMenu->Check(ID_SHOW_EARS, true);
charMenu->AppendCheckItem(ID_SHOW_HAIR, _("Show Hair\tCTRL+H"));
charMenu->Check(ID_SHOW_HAIR, true);
charMenu->AppendCheckItem(ID_SHOW_FACIALHAIR, _("Show Facial Hair\tCTRL+F"));
charMenu->Check(ID_SHOW_FACIALHAIR, true);
charMenu->AppendCheckItem(ID_SHOW_FEET, _("Show Feet"));
charMenu->Check(ID_SHOW_FEET, false);
charMenu->AppendCheckItem(ID_SHEATHE, _("Sheathe Weapons\tCTRL+Z"));
charMenu->Check(ID_SHEATHE, false);
charMenu->AppendSeparator();
charMenu->Append(ID_SAVE_EQUIPMENT, _("Save Equipment\tF5"));
charMenu->Append(ID_LOAD_EQUIPMENT, _("Load Equipment\tF6"));
charMenu->Append(ID_CLEAR_EQUIPMENT, _("Clear Equipment\tF9"));
charMenu->AppendSeparator();
charMenu->Append(ID_LOAD_SET, _("Load Item Set"));
charMenu->Append(ID_LOAD_START, _("Load Start Outfit"));
charMenu->Append(ID_LOAD_NPC_START, _("Load NPC Outfit"));
charMenu->AppendSeparator();
charMenu->Append(ID_MOUNT_CHARACTER, _("Mount a character..."));
charMenu->Append(ID_CHAR_RANDOMISE, _("Randomise Character\tF10"));

// Start out Disabled.
charMenu->Enable(ID_SAVE_CHAR, false);
charMenu->Enable(ID_SHOW_UNDERWEAR, false);
charMenu->Enable(ID_SHOW_EARS, false);
charMenu->Enable(ID_SHOW_HAIR, false);
charMenu->Enable(ID_SHOW_FACIALHAIR, false);
charMenu->Enable(ID_SHOW_FEET, false);
charMenu->Enable(ID_SHEATHE, false);
charMenu->Enable(ID_SAVE_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_EQUIPMENT, false);
charMenu->Enable(ID_CLEAR_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_SET, false);
charMenu->Enable(ID_LOAD_START, false);
charMenu->Enable(ID_LOAD_NPC_START, false);
charMenu->Enable(ID_MOUNT_CHARACTER, false);
charMenu->Enable(ID_CHAR_RANDOMISE, false);

wxMenu *effectsMenu = new wxMenu;
effectsMenu->Append(ID_ENCHANTS, _("Apply Enchants"));
effectsMenu->Append(ID_EQCREATURE_R, _("Creature Right-Hand"));
effectsMenu->Append(ID_EQCREATURE_L, _("Creature Left-Hand"));
#ifndef WotLK
effectsMenu->Append(ID_SPELLS, _("Spell Effects"));
effectsMenu->Enable(ID_SPELLS, false);
effectsMenu->Append(ID_SHADER_DEATH, _("Death Effect"));
effectsMenu->Enable(ID_SHADER_DEATH, false);
effectsMenu->Append(ID_TEST, _T("TEST"));
#endif

// Options menu
optMenu = new wxMenu;
#ifndef WotLK
optMenu->AppendCheckItem(ID_USE_NPCSKINS, _("Use npc character skins"));
optMenu->Check(ID_USE_NPCSKINS, false);
#endif
optMenu->AppendCheckItem(ID_DEFAULT_DOODADS, _("Always show default doodads in WMOs"));
optMenu->Check(ID_DEFAULT_DOODADS, true);
optMenu->AppendSeparator();
optMenu->Append(ID_MODELEXPORT_OPTIONS, _("Export Options..."));
optMenu->Append(ID_SHOW_SETTINGS, _("Settings..."));


wxMenu *aboutMenu = new wxMenu;
aboutMenu->Append(ID_LANGUAGE, _("Language"));
aboutMenu->Append(ID_HELP, _("Help"));
aboutMenu->Enable(ID_HELP, false);
aboutMenu->Append(ID_ABOUT, _("About"));
aboutMenu->AppendSeparator();
aboutMenu->Append(ID_CHECKFORUPDATE, _("Check for Update"));

menuBar = new wxMenuBar();
menuBar->Append(fileMenu, _("&File"));
menuBar->Append(viewMenu, _("&View"));
menuBar->Append(charMenu, _("&Character"));
menuBar->Append(lightMenu, _("&Lighting"));
menuBar->Append(optMenu, _("&Options"));
menuBar->Append(effectsMenu, _("&Effects"));
menuBar->Append(aboutMenu, _("&About"));
SetMenuBar(menuBar);
} catch(...) {};

// Disable our "Character" menu, only accessible when a character model is being displayed
// menuBar->EnableTop(2, false);

// Hotkeys / shortcuts
wxAcceleratorEntry entries[26];
entries[0].Set(wxACCEL_NORMAL, WXK_F5, ID_SAVE_EQUIPMENT);
entries[1].Set(wxACCEL_NORMAL, WXK_F6, ID_LOAD_EQUIPMENT);
entries[2].Set(wxACCEL_NORMAL, WXK_F7, ID_SAVE_CHAR);
entries[3].Set(wxACCEL_NORMAL, WXK_F8, ID_LOAD_CHAR);
entries[4].Set(wxACCEL_CTRL, (int)'b', ID_SHOW_BOUNDS);
//entries[5].Set(wxACCEL_NORMAL, (int)'B', ID_SHOW_BOUNDS);
entries[6].Set(wxACCEL_CTRL, (int)'X', ID_FILE_EXIT);
entries[7].Set(wxACCEL_NORMAL, WXK_F12, ID_FILE_SCREENSHOT);
entries[8].Set(wxACCEL_CTRL, (int)'e', ID_SHOW_EARS);
entries[9].Set(wxACCEL_CTRL, (int)'h', ID_SHOW_HAIR);
entries[10].Set(wxACCEL_CTRL, (int)'f', ID_SHOW_FACIALHAIR);
entries[11].Set(wxACCEL_CTRL, (int)'z', ID_SHEATHE);
entries[12].Set(wxACCEL_CTRL, (int)'l', ID_BACKGROUND);
entries[13].Set(wxACCEL_CTRL, (int)'+', ID_ZOOM_IN);
entries[14].Set(wxACCEL_CTRL, (int)'-', ID_ZOOM_OUT);
entries[15].Set(wxACCEL_CTRL, (int)'s', ID_FILE_SCREENSHOTCONFIG);
entries[16].Set(wxACCEL_NORMAL, WXK_F9, ID_CLEAR_EQUIPMENT);
entries[17].Set(wxACCEL_NORMAL, WXK_F10, ID_CHAR_RANDOMISE);

// Temporary saves
entries[18].Set(wxACCEL_NORMAL, WXK_F1, ID_SAVE_TEMP1);
entries[19].Set(wxACCEL_NORMAL, WXK_F2, ID_SAVE_TEMP2);
entries[20].Set(wxACCEL_NORMAL, WXK_F3, ID_SAVE_TEMP3);
entries[21].Set(wxACCEL_NORMAL, WXK_F4, ID_SAVE_TEMP4);

// Temp loads
entries[22].Set(wxACCEL_CTRL, WXK_F1, ID_LOAD_TEMP1);
entries[23].Set(wxACCEL_CTRL, WXK_F2, ID_LOAD_TEMP2);
entries[24].Set(wxACCEL_CTRL, WXK_F3, ID_LOAD_TEMP3);
entries[25].Set(wxACCEL_CTRL, WXK_F4, ID_LOAD_TEMP4);

wxAcceleratorTable accel(26, entries);
this->SetAcceleratorTable(accel);
}

void ModelViewer::InitObjects()
{
wxLogMessage(_T("Initiating Objects..."));

fileControl = new FileControl(this, ID_FILELIST_FRAME);

animControl = new AnimControl(this, ID_ANIM_FRAME);
charControl = new CharControl(this, ID_CHAR_FRAME);
lightControl = new LightControl(this, ID_LIGHT_FRAME);
modelControl = new ModelControl(this, ID_MODEL_FRAME);
settingsControl = new SettingsControl(this, ID_SETTINGS_FRAME);
settingsControl->Show(false);
modelbankControl = new ModelBankControl(this, ID_MODELBANK_FRAME);
modelOpened = new ModelOpened(this, ID_MODELOPENED_FRAME);
exportOptionsControl = new ModelExportOptions_Control(this, ID_EXPORTOPTIONS_FRAME);
exportOptionsControl->Show(false);

canvas = new ModelCanvas(this);

if (video.secondPass) {
canvas->Destroy();
video.Release();
canvas = new ModelCanvas(this);
}

g_modelViewer = this;
g_animControl = animControl;
g_charControl = charControl;
g_canvas = canvas;

modelControl->animControl = animControl;

enchants = new EnchantsDialog(this, charControl);

animExporter = new CAnimationExporter(this, wxID_ANY, _T("Animation Exporter"), wxDefaultPosition, wxSize(350, 220), wxCAPTION|wxSTAY_ON_TOP|wxFRAME_NO_TASKBAR);
}

void ModelViewer::InitDatabase()
{
wxLogMessage(_T("Initiating Databases..."));
initDB = true;

if (!itemdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Item DB."));
}
char filename[20];
if (langID == 5)
strncpy(filename, "zhTW/items.csv", sizeof(filename));
else if (langID == 4)
strncpy(filename, "zhCN/items.csv", sizeof(filename));
else
strncpy(filename, "enUS/items.csv", sizeof(filename));
if (!wxFile::Exists(wxString(filename, wxConvUTF8)))
strncpy(filename, "enUS/items.csv", sizeof(filename));
if (wxFile::Exists(wxString(filename, wxConvUTF8))) {
items.open(filename);
} else
wxLogMessage(_T("Error: Could not find items.csv to load an item list from."));

if (!skyboxdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the SkyBox DB."));
}
if (!spellitemenchantmentdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the SkyBox DB."));
}
if (!itemvisualsdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the SkyBox DB."));
}
if (!animdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Animation DB."));
}
if (!modeldb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Creatures DB."));
}
if (!skindb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the CreatureDisplayInfo DB."));
}
if(!hairdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Hair Geoset DB."));
}
if(!chardb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Character DB."));
}
if(!racedb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Char Races DB."));
}
if(!classdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Char Classes DB."));
}
if(!facialhairdb.open()) {
initDB = false;
wxLogMessage(_T("Error: Could not open the Char Facial Hair DB."));
}
if(!visualdb.open())
wxLogMessage(_T("Error: Could not open the ItemVisuals DB."));
if(!effectdb.open())
wxLogMessage(_T("Error: Could not open the ItemVisualEffects DB."));
if(!subclassdb.open())
wxLogMessage(_T("Error: Could not open the Item Subclasses DB."));
if(!startdb.open())
wxLogMessage(_T("Error: Could not open the Start Outfit Sets DB."));
//if(!helmetdb.open()) return false;
if(!npcdb.open())
wxLogMessage(_T("Error: Could not open the Start Outfit NPC DB."));
if(!npctypedb.open())
wxLogMessage(_T("Error: Could not open the Creature Type DB."));

if(!itemdisplaydb.open())
wxLogMessage(_T("Error: Could not open the ItemDisplayInfo DB."));
else
items.cleanup(itemdisplaydb);

if(!setsdb.open())
wxLogMessage(_T("Error: Could not open the Item Sets DB."));
else
setsdb.cleanup(items);

// char filename[20];
if (langID == 5)
strncpy(filename, "zhTW/npcs.csv", sizeof(filename));
else if (langID == 4)
strncpy(filename, "zhCN/npcs.csv", sizeof(filename));
else
strncpy(filename, "enUS/npcs.csv", sizeof(filename));
if(!wxFile::Exists(wxString(filename, wxConvUTF8)))
strncpy(filename, "enUS/npcs.csv", sizeof(filename));
if(wxFile::Exists(wxString(filename, wxConvUTF8)))
npcs.open(filename);
else {
NPCRecord rec("26499,24949,7,Arthas");
if (rec.model > 0) {
npcs.npcs.push_back(rec);
}
wxLogMessage(_T("Error: Could not find npcs.csv, unable to create NPC list."));
}

if(spelleffectsdb.open())
GetSpellEffects();
else
wxLogMessage(_T("Error: Could not open the SpellVisualEffects DB."));

wxLogMessage(_T("Finished initiating database files."));
}

void ModelViewer::InitDocking()
{
wxLogMessage(_T("Initiating GUI Docking."));

// wxAUI stuff
//interfaceManager.SetFrame(this);
interfaceManager.SetManagedWindow(this);

// OpenGL Canvas
interfaceManager.AddPane(canvas, wxAuiPaneInfo().
Name(wxT("canvas")).Caption(_("OpenGL Canvas")).
CenterPane());

// Tree list control
interfaceManager.AddPane(fileControl, wxAuiPaneInfo().
Name(wxT("fileControl")).Caption(_("File List")).
BestSize(wxSize(170,700)).Left().Layer(2));

// Animation frame
interfaceManager.AddPane(animControl, wxAuiPaneInfo().
Name(wxT("animControl")).Caption(_("Animation")).
Bottom().Layer(1));

// Character frame
interfaceManager.AddPane(charControl, wxAuiPaneInfo().
Name(wxT("charControl")).Caption(_("Character")).
BestSize(wxSize(170,700)).Right().Layer(2).Show(isChar));

// Lighting control
interfaceManager.AddPane(lightControl, wxAuiPaneInfo().
Name(wxT("Lighting")).Caption(_("Lighting")).
FloatingSize(wxSize(170,430)).Float().Fixed().Show(false).
DestroyOnClose(false)); //.FloatingPosition(GetStartPosition())

// model control
interfaceManager.AddPane(modelControl, wxAuiPaneInfo().
Name(wxT("Models")).Caption(_("Models")).
FloatingSize(wxSize(160,460)).Float().Show(false).
DestroyOnClose(false));

// model bank control
interfaceManager.AddPane(modelbankControl, wxAuiPaneInfo().
Name(_T("ModelBank")).Caption(_("ModelBank")).
FloatingSize(wxSize(300,320)).Float().Fixed().Show(false).
DestroyOnClose(false));

// model opened
interfaceManager.AddPane(modelOpened, wxAuiPaneInfo().
Name(wxT("ModelOpened")).Caption(_("ModelOpened")).
FloatingSize(wxSize(700,90)).Float().Fixed().Show(false).
DestroyOnClose(false));

// settings frame
interfaceManager.AddPane(settingsControl, wxAuiPaneInfo().
Name(wxT("Settings")).Caption(_("Settings")).
FloatingSize(wxSize(400,440)).Float().TopDockable(false).LeftDockable(false).
RightDockable(false).BottomDockable(false).Fixed().Show(false));

interfaceManager.AddPane(exportOptionsControl, wxAuiPaneInfo().
Name(wxT("ExportOptions")).Caption(_("Model Export Options")).
FloatingSize(wxSize(400,440)).Float().TopDockable(false).LeftDockable(false).
RightDockable(false).BottomDockable(false).Fixed().Show(false));

// tell the manager to "commit" all the changes just made
//interfaceManager.Update();
}

void ModelViewer::ResetLayout()
{
interfaceManager.DetachPane(fileControl);
interfaceManager.DetachPane(animControl);
interfaceManager.DetachPane(charControl);
interfaceManager.DetachPane(lightControl);
interfaceManager.DetachPane(modelControl);
interfaceManager.DetachPane(settingsControl);
interfaceManager.DetachPane(exportOptionsControl);
interfaceManager.DetachPane(canvas);

// OpenGL Canvas
interfaceManager.AddPane(canvas, wxAuiPaneInfo().
Name(wxT("canvas")).Caption(_("OpenGL Canvas")).
CenterPane());

// Tree list control
interfaceManager.AddPane(fileControl, wxAuiPaneInfo().
Name(wxT("fileControl")).Caption(_("File List")).
BestSize(wxSize(170,700)).Left().Layer(2));

// Animation frame
interfaceManager.AddPane(animControl, wxAuiPaneInfo().
Name(wxT("animControl")).Caption(_("Animation")).
Bottom().Layer(1));

// Character frame
interfaceManager.AddPane(charControl, wxAuiPaneInfo().
Name(wxT("charControl")).Caption(_("Character")).
BestSize(wxSize(170,700)).Right().Layer(2).Show(isChar));

interfaceManager.AddPane(lightControl, wxAuiPaneInfo().
Name(wxT("Lighting")).Caption(_("Lighting")).
FloatingSize(wxSize(170,430)).Float().Fixed().Show(false).
DestroyOnClose(false)); //.FloatingPosition(GetStartPosition())

interfaceManager.AddPane(modelControl, wxAuiPaneInfo().
Name(wxT("Models")).Caption(_("Models")).
FloatingSize(wxSize(160,460)).Float().Show(false).
DestroyOnClose(false));

interfaceManager.AddPane(settingsControl, wxAuiPaneInfo().
Name(wxT("Settings")).Caption(_("Settings")).
FloatingSize(wxSize(400,440)).Float().TopDockable(false).LeftDockable(false).
RightDockable(false).BottomDockable(false).Show(false));

interfaceManager.AddPane(exportOptionsControl, wxAuiPaneInfo().
Name(wxT("ExportOptions")).Caption(_("Model Export Options")).
FloatingSize(wxSize(400,440)).Float().TopDockable(false).LeftDockable(false).
RightDockable(false).BottomDockable(false).Show(false));

// tell the manager to "commit" all the changes just made
interfaceManager.Update();
}


void ModelViewer::LoadSession()
{
wxLogMessage(_T("Loading Session settings from: %s\n"), cfgPath.c_str());

// Application Config Settings
wxFileConfig *pConfig = new wxFileConfig(_T("Global"),wxEmptyString, cfgPath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);

// Other session settings
if (canvas) {
pConfig->SetPath(_T("/Session"));
double c;
// Background Colour
pConfig->Read(_T("bgR"), &c, 71.0/255);
canvas->vecBGColor.x = c;
pConfig->Read(_T("bgG"), &c, 95.0/255);
canvas->vecBGColor.y = c;
pConfig->Read(_T("bgB"), &c, 121.0/255);
canvas->vecBGColor.z = c;

// boolean vars
pConfig->Read(_T("RandomLooks"), &useRandomLooks, true);
pConfig->Read(_T("HideHelmet"), &bHideHelmet, false);
pConfig->Read(_T("ShowParticle"), &bShowParticle, true);
pConfig->Read(_T("KnightEyeGlow"), &bKnightEyeGlow, true);
pConfig->Read(_T("DBackground"), &canvas->drawBackground, false);
pConfig->Read(_T("BackgroundImage"), &bgImagePath, _T(""));
if (bgImagePath != _T("")) {
canvas->LoadBackground(bgImagePath);
//viewMenu->Check(ID_BACKGROUND, canvas->drawBackground);
}


// model file
/*wxString modelfn;
pConfig->Read(_T("Model"), &modelfn);
if (modelfn) {
LoadModel(modelfn);
}*/
}

wxDELETE(pConfig);
}

void ModelViewer::SaveSession()
{
// Application Config Settings
wxFileConfig *pConfig = new wxFileConfig(_T("Global"), wxEmptyString, cfgPath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);


// Graphic / Video display settings
pConfig->SetPath(_T("/Graphics"));
pConfig->Write(_T("FSAA"), video.curCap.aaSamples);
pConfig->Write(_T("AccumulationBuffer"), video.curCap.accum);
pConfig->Write(_T("AlphaBits"), video.curCap.alpha);
pConfig->Write(_T("ColourBits"), video.curCap.colour);
pConfig->Write(_T("DoubleBuffer"), video.curCap.doubleBuffer);
pConfig->Write(_T("HWAcceleration"), video.curCap.hwAcc);
pConfig->Write(_T("SampleBuffer"), video.curCap.sampleBuffer);
pConfig->Write(_T("StencilBuffer"), video.curCap.stencil);
pConfig->Write(_T("ZBuffer"), video.curCap.zBuffer);



pConfig->SetPath(_T("/Session"));
// Attempt at saving colour values as 3 byte hex - loss of accuracy from float
//wxString temp(Vec3DToString(canvas->vecBGColor));

if (canvas) {
pConfig->Write(_T("bgR"), (double)canvas->vecBGColor.x);
pConfig->Write(_T("bgG"), (double)canvas->vecBGColor.y);
pConfig->Write(_T("bgB"), (double)canvas->vecBGColor.z);

// boolean vars
pConfig->Write(_T("RandomLooks"), useRandomLooks);
pConfig->Write(_T("HideHelmet"), bHideHelmet);
pConfig->Write(_T("ShowParticle"), bShowParticle);
pConfig->Write(_T("KnightEyeGlow"), bKnightEyeGlow);

pConfig->Write(_T("DBackground"), canvas->drawBackground);
if (canvas->drawBackground)
pConfig->Write(_T("BackgroundImage"), bgImagePath);
else
pConfig->Write(_T("BackgroundImage"), _T(""));

// model file
if (canvas->model)
pConfig->Write(_T("Model"), wxString(canvas->model->name.c_str(), wxConvUTF8));
}

// character details
// equipment

wxDELETE(pConfig);
}

void ModelViewer::LoadLayout()
{
// Application Config Settings
wxFileConfig *pConfig = new wxFileConfig(_T("Global"), wxEmptyString, cfgPath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);

wxString layout;

// Get layout data
pConfig->SetPath(_T("/Session"));
pConfig->Read(_T("Layout"), &layout);

// if the layout data exists, load it.
if (!layout.IsNull() && !layout.IsEmpty()) {
if (!interfaceManager.LoadPerspective(layout, false))
wxLogMessage(_T("Error: Could not load the layout."));
else {
// No need to display these windows on startup
interfaceManager.GetPane(modelControl).Show(false);
interfaceManager.GetPane(modelOpened).Show(false);
interfaceManager.GetPane(settingsControl).Show(false);
interfaceManager.GetPane(exportOptionsControl).Show(false);

// If character panel is showing, hide it
interfaceManager.GetPane(charControl).Show(isChar);

interfaceManager.Update();

wxLogMessage(_T("Info: GUI Layout loaded from previous session."));
}
}

wxDELETE(pConfig);
}

void ModelViewer::SaveLayout()
{
// Application Config Settings
wxFileConfig *pConfig = new wxFileConfig(_T("Global"), wxEmptyString, cfgPath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);

pConfig->SetPath(_T("/Session"));

// Save GUI layout data
wxString layout = interfaceManager.SavePerspective();
pConfig->Write(_T("Layout"), layout);

wxLogMessage(_T("Info: GUI Layout was saved."));

wxDELETE(pConfig);
}


void ModelViewer::LoadModel(const wxString fn)
{
if (!canvas || fn.IsEmpty())
return;

isModel = true;

// check if this is a character model
isChar = (fn.Mid(0,4).IsSameAs(_T("Char"), false));

Attachment *modelAtt = NULL;

if (isChar) {
modelAtt = canvas->LoadCharModel(fn.fn_str());

// error check
if (!modelAtt) {
wxLogMessage(_T("Error: Failed to load the model - %s"), fn.c_str());
return;
}

canvas->model->modelType = MT_CHAR;

} else {
modelAtt = canvas->LoadCharModel(fn.fn_str()); // change it from LoadModel, don't sure it's right or not.

// error check
if (!modelAtt) {
wxLogMessage(_T("Error: Failed to load the model - %s"), fn.c_str());
return;
}

canvas->model->modelType = MT_NORMAL;
}

// Error check, make sure the model was actually loaded and set to canvas->model
if (!canvas->model) {
wxLogMessage(_T("Error: [ModelViewer::LoadModel()] Model* Canvas::model is null!"));
return;
}

canvas->model->charModelDetails.isChar = isChar;

viewMenu->Enable(ID_USE_CAMERA, canvas->model->hasCamera);
if (canvas->useCamera && !canvas->model->hasCamera) {
canvas->useCamera = false;
viewMenu->Check(ID_USE_CAMERA, false);
}

// wxAUI
interfaceManager.GetPane(charControl).Show(isChar);
if (isChar) {
charMenu->Check(ID_SHOW_UNDERWEAR, true);
charMenu->Check(ID_SHOW_EARS, true);
charMenu->Check(ID_SHOW_HAIR, true);
charMenu->Check(ID_SHOW_FACIALHAIR, true);

charMenu->Enable(ID_SAVE_CHAR, true);
charMenu->Enable(ID_SHOW_UNDERWEAR, true);
charMenu->Enable(ID_SHOW_EARS, true);
charMenu->Enable(ID_SHOW_HAIR, true);
charMenu->Enable(ID_SHOW_FACIALHAIR, true);
charMenu->Enable(ID_SHOW_FEET, true);
charMenu->Enable(ID_SHEATHE, true);
charMenu->Enable(ID_SAVE_EQUIPMENT, true);
charMenu->Enable(ID_LOAD_EQUIPMENT, true);
charMenu->Enable(ID_CLEAR_EQUIPMENT, true);
charMenu->Enable(ID_LOAD_SET, true);
charMenu->Enable(ID_LOAD_START, true);
charMenu->Enable(ID_LOAD_NPC_START, true);
charMenu->Enable(ID_MOUNT_CHARACTER, true);
charMenu->Enable(ID_CHAR_RANDOMISE, true);

charControl->UpdateModel(modelAtt);
} else {
charControl->charAtt = modelAtt;
charControl->model = (Model*)modelAtt->model;

charMenu->Enable(ID_SAVE_CHAR, false);
charMenu->Enable(ID_SHOW_UNDERWEAR, false);
charMenu->Enable(ID_SHOW_EARS, false);
charMenu->Enable(ID_SHOW_HAIR, false);
charMenu->Enable(ID_SHOW_FACIALHAIR, false);
charMenu->Enable(ID_SHOW_FEET, false);
charMenu->Enable(ID_SHEATHE, false);
charMenu->Enable(ID_SAVE_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_EQUIPMENT, false);
charMenu->Enable(ID_CLEAR_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_SET, false);
charMenu->Enable(ID_LOAD_START, false);
charMenu->Enable(ID_LOAD_NPC_START, false);
charMenu->Enable(ID_MOUNT_CHARACTER, false);
charMenu->Enable(ID_CHAR_RANDOMISE, false);
}

// Update the model control
modelControl->UpdateModel(modelAtt);
modelControl->RefreshModel(canvas->root);

// Update the animations / skins
animControl->UpdateModel(canvas->model);

interfaceManager.Update();
}

// Load an NPC model
void ModelViewer::LoadNPC(unsigned int modelid)
{
canvas->clearAttachments();
//if (!isChar) // may memory leak
// wxDELETE(canvas->model);
canvas->model = NULL;

isModel = true;
isChar = false;
isWMO = false;

try {
CreatureSkinDB::Record modelRec = skindb.getBySkinID(modelid);
int displayID = modelRec.getUInt(CreatureSkinDB::NPCID);

// if the creature ID ISN'T a "NPC", then load the creature model and skin it.
if (displayID == 0) {

unsigned int modelID = modelRec.getUInt(CreatureSkinDB::ModelID);
CreatureModelDB::Record creatureModelRec = modeldb.getByID(modelID);

wxString name(creatureModelRec.getString(CreatureModelDB::Filename));
name = name.BeforeLast('.');
name.Append(_T(".m2"));

LoadModel(name);
canvas->model->modelType = MT_NORMAL;

TextureGroup grp;
int count = 0;
for (int i=0; i<TextureGroup::num; i++) {
wxString skin(modelRec.getString(CreatureSkinDB::Skin + i));

grp.tex[i] = skin.mb_str();
if (skin.length() > 0)
count++;
}
grp.base = 11;
grp.count = count;
if (grp.tex[0].length() > 0)
animControl->AddSkin(grp);

} else {
isChar = true;
NPCDB::Record rec = npcdb.getByNPCID(displayID);
CharRacesDB::Record rec2 = racedb.getById(rec.getUInt(NPCDB::RaceID));

wxString retval = rec.getString(NPCDB::Gender);
wxString strModel = _T("Character\\");

if (gameVersion == 30100) {
if (retval != _T("")) {
strModel.append(rec2.getString(CharRacesDB::NameV310));
strModel.append(_T("\\Female\\"));
strModel.append(rec2.getString(CharRacesDB::NameV310));
strModel.append(_T("Female.m2"));
} else {
strModel.append(rec2.getString(CharRacesDB::NameV310));
strModel.append(_T("\\Male\\"));
strModel.append(rec2.getString(CharRacesDB::NameV310));
strModel.append(_T("Male.m2"));
}
} else {
if (retval != _T("")) {
strModel.append(rec2.getString(CharRacesDB::Name));
strModel.append(_T("\\Female\\"));
strModel.append(rec2.getString(CharRacesDB::Name));
strModel.append(_T("Female.m2"));
} else {
strModel.append(rec2.getString(CharRacesDB::Name));
strModel.append(_T("\\Male\\"));
strModel.append(rec2.getString(CharRacesDB::Name));
strModel.append(_T("Male.m2"));
}
}

//const char *newName = strModel.c_str();

Attachment *modelAtt;
modelAtt = canvas->LoadCharModel(strModel.mb_str());
canvas->model->modelType = MT_NPC;

wxString fn(_T("Textures\\Bakednpctextures\\"));
fn.Append(rec.getString(NPCDB::Filename));
charControl->UpdateNPCModel(modelAtt, displayID);
charControl->customSkin = fn;

charControl->RefreshNPCModel(); // rec.getUInt(NPCDB::NPCID
charControl->RefreshEquipment();

menuBar->EnableTop(2, true);
charMenu->Check(ID_SHOW_UNDERWEAR, true);
charMenu->Check(ID_SHOW_EARS, true);
charMenu->Check(ID_SHOW_HAIR, true);
charMenu->Check(ID_SHOW_FACIALHAIR, true);
// ---

animControl->UpdateModel(canvas->model);
canvas->ResetView();
}
} catch (...) {}

// wxAUI
interfaceManager.GetPane(charControl).Show(isChar);
interfaceManager.Update();
}

void ModelViewer::LoadItem(unsigned int displayID)
{
canvas->clearAttachments();
//if (!isChar) // may memory leak
// wxDELETE(canvas->model);
canvas->model = NULL;

isModel = true;
isChar = false;
isWMO = false;

try {
ItemDisplayDB::Record modelRec = itemdisplaydb.getById(displayID);
wxString name = modelRec.getString(ItemDisplayDB::Model);
name = name.BeforeLast('.');
name.Append(_T(".M2"));
//wxLogMessage(_T("LoadItem %d %s"), displayID, name.c_str());

wxString fns[] = { _T("Item\\ObjectComponents\\Head\\"),
_T("Item\\ObjectComponents\\Shoulder\\"),
_T("Item\\ObjectComponents\\Quiver\\"),
_T("Item\\ObjectComponents\\Shield\\"),
_T("Item\\ObjectComponents\\Weapon\\") };
wxString fn;
for(int i=0; i<5; i++) {
fn = fns[i]+name;
if (MPQFile::getSize(fn.fn_str()) > 0) {
LoadModel(fn);
break;
}
}
charMenu->Enable(ID_SAVE_CHAR, false);
charMenu->Enable(ID_SHOW_UNDERWEAR, false);
charMenu->Enable(ID_SHOW_EARS, false);
charMenu->Enable(ID_SHOW_HAIR, false);
charMenu->Enable(ID_SHOW_FACIALHAIR, false);
charMenu->Enable(ID_SHOW_FEET, false);
charMenu->Enable(ID_SHEATHE, false);
charMenu->Enable(ID_SAVE_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_EQUIPMENT, false);
charMenu->Enable(ID_CLEAR_EQUIPMENT, false);
charMenu->Enable(ID_LOAD_SET, false);
charMenu->Enable(ID_LOAD_START, false);
charMenu->Enable(ID_LOAD_NPC_START, false);
charMenu->Enable(ID_MOUNT_CHARACTER, false);
charMenu->Enable(ID_CHAR_RANDOMISE, false);

} catch (...) {}

// wxAUI
interfaceManager.GetPane(charControl).Show(isChar);
interfaceManager.Update();
}

// This is called when the user goes to File->Exit
void ModelViewer::OnExit(wxCommandEvent &event)
{
if (event.GetId() == ID_FILE_EXIT) {
video.render = false;
//canvas->timer.Stop();
canvas->Disable();
Close(false);
}
}

// This is called when the window is closing
void ModelViewer::OnClose(wxCloseEvent &event)
{
Destroy();
}

// Called when the window is resized, minimised, etc
void ModelViewer::OnSize(wxSizeEvent &event)
{
/* // wxIFM stuff
if(!interfaceManager)
event.Skip();
else
interfaceManager->Update(IFM_DEFAULT_RECT);
*/

// wxAUI
//interfaceManager.Update(); // causes an error?
}

ModelViewer::~ModelViewer()
{
wxLogMessage(_T("Shuting down the program...\n"));

video.render = false;

// If we have a canvas (which we always should)
// Stop rendering, give more power back to the CPU to close this sucker down!
//if (canvas)
// canvas->timer.Stop();

// Save current layout
SaveLayout();

// wxAUI stuff
interfaceManager.UnInit();

// Clear the MPQ archives.
for (std::vector<MPQArchive*>::iterator it = archives.begin(); it != archives.end(); ++it) {
(*it)->close();
//archives.erase(it);
}
archives.clear();

// Save our session and layout info
SaveSession();

if (animExporter) {
animExporter->Destroy();
wxDELETE(animExporter);
}

if (canvas) {
canvas->Disable();
canvas->Destroy();
canvas = NULL;
}

if (fileControl) {
fileControl->Destroy();
fileControl = NULL;
}

if (animControl) {
animControl->Destroy();
animControl = NULL;
}

if (charControl) {
charControl->Destroy();
charControl = NULL;
}

if (lightControl) {
lightControl->Destroy();
lightControl = NULL;
}

if (settingsControl) {
settingsControl->Destroy();
settingsControl = NULL;
}

if (exportOptionsControl) {
exportOptionsControl->Destroy();
exportOptionsControl = NULL;
}

if (modelControl) {
modelControl->Destroy();
modelControl = NULL;
}

if (modelOpened) {
modelOpened->Destroy();
modelOpened = NULL;
}

if (enchants) {
enchants->Destroy();
enchants = NULL;
}
}

bool ModelViewer::InitMPQArchives()
{
wxString path;

for (size_t i=0; i<mpqArchives.GetCount(); i++) {
if (wxFileName::FileExists(mpqArchives[i]))
archives.push_back(new MPQArchive(mpqArchives[i].mb_str()));
}

// Checks and logs the "TOC" version of the interface files that were loaded
MPQFile f("Interface\\FrameXML\\FrameXML.TOC");
if (f.isEof()) {
f.close();
wxLogMessage(_T("Unable to gather TOC data."));
return false;
}
f.seek(51); // offset to "## Interface: "
unsigned char toc[6];
memset(toc,'\0', 6);
f.read(toc, 5);
f.close();
wxLogMessage(_T("Loaded Content TOC: v%c.%c%c.%c%c"), toc[0], toc[1], toc[2], toc[3], toc[4]);

wxString info = _T("Notice: WMV is designed for WoW 3.3.x, but your version is supported.\nYou may experience diminished capacity while working with WoW Model Viewer.\nYou should update your World of Warcraft client soon.");
// If we support more than 1 TOC version, place the others here.
if (strncmp((char*)toc, "30100", 5) == 0){
if (gameVersion != 30100){
wxMessageBox(info,_T("Compatible Version Found."),wxOK);
gameVersion = 30100;
}
}else if (strncmp((char*)toc, "30200", 5) == 0){
wxLogMessage(info);
if (gameVersion != 30200){
wxMessageBox(info,_T("Compatible Version Found."),wxOK);
gameVersion = 30200;
}
}else if (strncmp((char*)toc, "40000", 5) == 0) {
wxLogMessage(info);
if (gameVersion != 40000){
wxString info = _T("Notice: Cataclysm is still under development.\nMissing or incorrect data may not be a WMV issue.");
wxMessageBox(info,_T("Cataclysm Detected!"),wxOK);
gameVersion = 40000;
}
langOffset = 0;
// else if not our primary supported edition...
}else if (strncmp((char*)toc, "30300", 5) != 0){
wxString info = _T("Notice: WoW Model Viewer does not support your version of WoW.\nPlease update your World of Warcraft client!");
wxLogMessage(info);

return false;
}else{
gameVersion = 30300;
}

const char *component = "component.wow-data.txt";
MPQFile f2(component);
if (!f2.isEof()) {
f2.save(component);
f2.close();

wxXmlDocument xmlDoc;
if (xmlDoc.Load(wxString(component, wxConvUTF8), _T("UTF-8"))) {
wxXmlNode *child = xmlDoc.GetRoot()->GetChildren(); // componentinfo->component.version
if (child && child->GetName() == _T("component")) {
wxString version = child->GetPropVal(_T("version"), _T("0"));
if (version != _T("0")) {
wxLogMessage(_T("Loaded Content Version: %s"), version.c_str());
}
}
}

wxRemoveFile(wxString(component, wxConvUTF8));
}
return true;
}

bool ModelViewer::Init()
{
/*
// Set our display mode
//if (video.GetCompatibleWinMode(video.curCap)) {
video.SetMode();
if (!video.render) // Something bad must of happened - find a new working display mode
video.GetAvailableMode();
/*
} else {
wxLogMessage(_T("Error: Failed to find a compatible graphics mode. Finding first available display mode..."));
video.GetAvailableMode(); // Get first available display mode that supports the current desktop colour bitdepth
}
*/

wxLogMessage(_T("Setting OpenGL render state..."));
video.InitGL();

// Initiate other stuff
wxLogMessage(_T("Initiating Archives...\n"));

// more detail logging, this is so when someone has a problem and they send their log info
wxLogMessage(_T("Game Data Path: %s"), wxString(gamePath.fn_str(), wxConvUTF8).c_str());
wxLogMessage(_T("Use Local Files: %s\n"), useLocalFiles ? _T("true") : _T("false"));

isChar = false;
isModel = false;
bool mpqarch = true;

// Load the games MPQ files into memory
mpqarch = InitMPQArchives();
wxLogMessage(_T("InitMPQArchives result: %s"),mpqarch ? _T("true") : _T("false"));

if (mpqarch == false){
return false;
}

fileControl->Init(this);

charControl->Init();

return true;
}

bool filterModels(std::string s)
{
//s.LowerCase();
const size_t len = s.length();
if (len < 4)
return false;

//return ((s[len-2]=='m' && s[len-1]=='2') || (s[len-3]=='w' && s[len-2]=='m'));
return (
((s[len-2]|0x20)=='m' && s[len-1]=='2')
|| ((s[len-3]|0x20)=='w' && (s[len-2]|0x20)=='m' && (s[len-1]|0x20)=='o' )
//||((s[len-3]|0x20)=='a' && (s[len-2]|0x20)=='d' && (s[len-1]|0x20)=='t' )
);
}

/*
bool filterNpcs(std::string s)
{
// textures\BakedNpcTextures\*.*
if (s.length() < 18)
return false;

return (s.substr(9, 8) == "BakedNpc");
}
*/

bool filterSounds(std::string s)
{
const size_t len = s.length();
if (len < 4)
return false;

return (
((s[len-3]|0x20)=='w' && (s[len-2]|0x20)=='a' && (s[len-1]|0x20)=='v') ||
((s[len-3]|0x20)=='m' && (s[len-2]|0x20)=='p' && s[len-1]=='3')
);
}



// Menu button press events
void ModelViewer::OnToggleDock(wxCommandEvent &event)
{
int id = event.GetId();

// wxAUI Stuff
if (id==ID_SHOW_FILE_LIST)
interfaceManager.GetPane(fileControl).Show(true);
else if (id==ID_SHOW_ANIM)
interfaceManager.GetPane(animControl).Show(true);
else if (id==ID_SHOW_CHAR && isChar)
interfaceManager.GetPane(charControl).Show(true);
else if (id==ID_SHOW_LIGHT)
interfaceManager.GetPane(lightControl).Show(true);
else if (id==ID_SHOW_MODEL)
interfaceManager.GetPane(modelControl).Show(true);
else if (id==ID_SHOW_SETTINGS) {
interfaceManager.GetPane(settingsControl).Show(true);
settingsControl->Open();
} else if (id==ID_SHOW_MODELBANK) {
interfaceManager.GetPane(modelbankControl).Show(true);
} else if (id==ID_SHOW_MODELOPENED) {
interfaceManager.GetPane(modelOpened).Show(true);
}else if(id==ID_MODELEXPORT_OPTIONS){
interfaceManager.GetPane(exportOptionsControl).Show(true);
exportOptionsControl->Open();
}
interfaceManager.Update();
}

// Menu button press events
void ModelViewer::OnToggleCommand(wxCommandEvent &event)
{
int id = event.GetId();

//switch
switch(id) {
case ID_FILE_RESETLAYOUT:
ResetLayout();
break;

/*
case ID_USE_ANTIALIAS:
useAntiAlias = event.IsChecked();
break;


case ID_USE_HWACC:
if (event.IsChecked() == true)
disableHWAcc = false;
else
disableHWAcc = true;
break;
*/

case ID_USE_ENVMAP:
video.useEnvMapping = event.IsChecked();
break;

case ID_SHOW_MASK:
video.useMasking = !video.useMasking;

case ID_SHOW_BOUNDS:
canvas->model->showBounds = !canvas->model->showBounds;
break;

case ID_SHOW_GRID:
canvas->drawGrid = event.IsChecked();
break;

case ID_USE_CAMERA:
canvas->useCamera = event.IsChecked();
break;

case ID_DEFAULT_DOODADS:
// if we have a model...
if (canvas->wmo) {
canvas->wmo->includeDefaultDoodads = event.IsChecked();
canvas->wmo->updateModels();
}
animControl->defaultDoodads = event.IsChecked();
break;

case ID_SAVE_CHAR:
{
wxFileDialog saveDialog(this, _("Save character"), wxEmptyString, wxEmptyString, _T("Character files (*.chr)|*.chr"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (saveDialog.ShowModal()==wxID_OK) {
SaveChar(saveDialog.GetPath().mb_str());
}
}
break;
case ID_LOAD_CHAR:
{
wxFileDialog loadDialog(this, _("Load character"), wxEmptyString, wxEmptyString, _T("Character files (*.chr)|*.chr"), wxFD_OPEN|wxFD_FILE_MUST_EXIST);
if (loadDialog.ShowModal()==wxID_OK) {
for (int i=0; i<NUM_CHAR_SLOTS; i++)
charControl->cd.equipment[i] = 0;

LoadChar(loadDialog.GetPath().mb_str());
}
}
break;

case ID_IMPORT_CHAR:
{
wxTextEntryDialog dialog(this, _T("Please paste in the URL to the character you wish to import."), _T("Please enter text"), wxEmptyString, wxOK | wxCANCEL | wxCENTRE, wxDefaultPosition);
if (dialog.ShowModal() == wxID_OK)
ImportArmoury(dialog.GetValue());
}
break;

case ID_ZOOM_IN:
canvas->Zoom(0.5f, false);
break;

case ID_ZOOM_OUT:
canvas->Zoom(-0.5f, false);
break;

case ID_SAVE_TEMP1:
canvas->SaveSceneState(1);
break;
case ID_SAVE_TEMP2:
canvas->SaveSceneState(2);
break;
case ID_SAVE_TEMP3:
canvas->SaveSceneState(3);
break;
case ID_SAVE_TEMP4:
canvas->SaveSceneState(4);
break;
case ID_LOAD_TEMP1:
canvas->LoadSceneState(1);
break;
case ID_LOAD_TEMP2:
canvas->LoadSceneState(2);
break;
case ID_LOAD_TEMP3:
canvas->LoadSceneState(3);
break;
case ID_LOAD_TEMP4:
canvas->LoadSceneState(4);
break;
case ID_MODELEXPORT_INIT:
modelExportInitOnly = exportMenu->IsChecked(ID_MODELEXPORT_INIT);
break;
}
}

void ModelViewer::OnLightMenu(wxCommandEvent &event)
{
int id = event.GetId();

switch (id) {
case ID_LT_SAVE:
{
wxFileDialog dialog(this, _("Save Lighting"), wxEmptyString, wxEmptyString, _T("Scene Lighting (*.lit)|*.lit"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);

if (dialog.ShowModal()==wxID_OK) {
wxString fn = dialog.GetFilename();

ofstream f(fn.fn_str(), ios_base::out|ios_base::trunc);
f << lightMenu->IsChecked(ID_LT_DIRECTION) << " " << lightMenu->IsChecked(ID_LT_TRUE) << " " << lightMenu->IsChecked(ID_LT_DIRECTIONAL) << " " << lightMenu->IsChecked(ID_LT_AMBIENT) << " " << lightMenu->IsChecked(ID_LT_MODEL) << endl;
for (int i=0; i<MAX_LIGHTS; i++) {
f << lightControl->lights[i].ambience.x << " " << lightControl->lights[i].ambience.y << " " << lightControl->lights[i].ambience.z << " " << lightControl->lights[i].arc << " " << lightControl->lights[i].constant_int << " " << lightControl->lights[i].diffuse.x << " " << lightControl->lights[i].diffuse.y << " " << lightControl->lights[i].diffuse.z << " " << lightControl->lights[i].enabled << " " << lightControl->lights[i].linear_int << " " << lightControl->lights[i].pos.x << " " << lightControl->lights[i].pos.y << " " << lightControl->lights[i].pos.z << " " << lightControl->lights[i].quadradic_int << " " << lightControl->lights[i].relative << " " << lightControl->lights[i].specular.x << " " << lightControl->lights[i].specular.y << " " << lightControl->lights[i].specular.z << " " << lightControl->lights[i].target.x << " " << lightControl->lights[i].target.y << " " << lightControl->lights[i].target.z << " " << lightControl->lights[i].type << endl;
}
f.close();
}

return;

} case ID_LT_LOAD: {
wxFileDialog dialog(this, _("Load Lighting"), wxEmptyString, wxEmptyString, _T("Scene Lighting (*.lit)|*.lit"), wxFD_OPEN|wxFD_FILE_MUST_EXIST);

if (dialog.ShowModal()==wxID_OK) {
wxString fn = dialog.GetFilename();
ifstream f(fn.fn_str());

bool lightObj, lightTrue, lightDir, lightAmb, lightModel;

//lightMenu->IsChecked(ID_LT_AMBIENT)
f >> lightObj >> lightTrue >> lightDir >> lightAmb >> lightModel;

lightMenu->Check(ID_LT_DIRECTION, lightObj);
lightMenu->Check(ID_LT_TRUE, lightTrue);
lightMenu->Check(ID_LT_DIRECTIONAL, lightDir);
lightMenu->Check(ID_LT_AMBIENT, lightAmb);
lightMenu->Check(ID_LT_MODEL, lightModel);

for (int i=0; i<MAX_LIGHTS; i++) {
f >> lightControl->lights[i].ambience.x >> lightControl->lights[i].ambience.y >> lightControl->lights[i].ambience.z >> lightControl->lights[i].arc >> lightControl->lights[i].constant_int >> lightControl->lights[i].diffuse.x >> lightControl->lights[i].diffuse.y >> lightControl->lights[i].diffuse.z >> lightControl->lights[i].enabled >> lightControl->lights[i].linear_int >> lightControl->lights[i].pos.x >> lightControl->lights[i].pos.y >> lightControl->lights[i].pos.z >> lightControl->lights[i].quadradic_int >> lightControl->lights[i].relative >> lightControl->lights[i].specular.x >> lightControl->lights[i].specular.y >> lightControl->lights[i].specular.z >> lightControl->lights[i].target.x >> lightControl->lights[i].target.y >> lightControl->lights[i].target.z >> lightControl->lights[i].type;
}
f.close();

if (lightObj)
canvas->drawLightDir = true;

if (lightDir) {
canvas->lightType = LIGHT_DYNAMIC; //LT_DIRECTIONAL;

/*
if (lightTrue) {
if (event.IsChecked()){
// Need to reset all our colour, lighting, material back to 'default'
//GLfloat b[] = {0.5f, 0.4f, 0.4f, 1.0f};
//glColor4fv(b);
glDisable(GL_COLOR_MATERIAL);

glMaterialfv(GL_FRONT, GL_EMISSION, def_emission);

glMaterialfv(GL_FRONT, GL_AMBIENT, def_ambience);
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, def_ambience);

glMaterialfv(GL_FRONT, GL_DIFFUSE, def_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, def_specular);
} else {
glEnable(GL_COLOR_MATERIAL);
}
}
*/
} else if (lightAmb) {
//glEnable(GL_COLOR_MATERIAL);
canvas->lightType = LIGHT_AMBIENT;
} else if (lightModel) {
canvas->lightType = LIGHT_MODEL_ONLY;
}

lightControl->UpdateGL();
lightControl->Update();
}

return;
}
/* case ID_USE_LIGHTS:
canvas->useLights = event.IsChecked();
return;
*/
case ID_LT_DIRECTION:
canvas->drawLightDir = event.IsChecked();
return;
case ID_LT_TRUE:
if (event.IsChecked()){
// Need to reset all our colour, lighting, material back to 'default'
//GLfloat b[] = {0.5f, 0.4f, 0.4f, 1.0f};
//glColor4fv(b);
glDisable(GL_COLOR_MATERIAL);

glMaterialfv(GL_FRONT, GL_EMISSION, def_emission);
glMaterialfv(GL_FRONT, GL_AMBIENT, def_ambience);
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, def_ambience);

glMaterialfv(GL_FRONT, GL_DIFFUSE, def_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, def_specular);
} else {
glEnable(GL_COLOR_MATERIAL);
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Vec4D(0.4f,0.4f,0.4f,1.0f));
}

lightControl->Update();

return;

// Ambient lighting
case ID_LT_AMBIENT:
//glEnable(GL_COLOR_MATERIAL);
canvas->lightType = LIGHT_AMBIENT;
return;

// Dynamic lighting
case ID_LT_DIRECTIONAL:
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, def_ambience);
canvas->lightType = LIGHT_DYNAMIC;
return;

// Model's ambient lighting
case ID_LT_MODEL:
canvas->lightType = LIGHT_MODEL_ONLY;
return;
}
}

void ModelViewer::OnCamMenu(wxCommandEvent &event)
{
int id = event.GetId();
if (id==ID_CAM_FRONT)
canvas->model->rot.y = -90.0f;
else if (id==ID_CAM_BACK)
canvas->model->rot.y = 90.0f;
else if (id==ID_CAM_SIDE)
canvas->model->rot.y = 0.0f;
else if (id==ID_CAM_ISO) {
canvas->model->rot.y = -40.0f;
canvas->model->rot.x = 20.0f;
}

//viewControl->Update();
}

// Menu button press events
void ModelViewer::OnSetColor(wxCommandEvent &event)
{
int id = event.GetId();
if (id==ID_BG_COLOR) {
canvas->vecBGColor = DoSetColor(canvas->vecBGColor);
canvas->drawBackground = false;
//} else if (id==ID_LT_COLOR) {
// canvas->ltColor = DoSetColor(canvas->ltColor);
}
}

// Menu button press events
void ModelViewer::OnEffects(wxCommandEvent &event)
{
int id = event.GetId();

if (id == ID_ENCHANTS) {
// Currently, only support enchanting character weapons
if (isChar)
enchants->Display();

} else if (id == ID_SPELLS) {
wxSingleChoiceDialog spellsDialog(this, _T("Choose"), _T("Select a Spell Effect"), spelleffects);

if (spellsDialog.ShowModal() == wxID_OK) {
// TODO: Finish adding support for spells.
}

} else if (id == ID_EQCREATURE_R) { // R for righthand
Model *m = static_cast<Model*>(canvas->root->model);
if (!m)
m = static_cast<Model*>(canvas->model);

// make sure m is a valid pointer to a model
if (m) {
// This is an error check to make sure the creature can be equipped.
for(int k=0; k<m->ATT_MAX; k++){
if (m->attLookup[k] == PS_RIGHT_PALM) {
SelectCreatureItem(CS_HAND_RIGHT, 0, charControl, canvas);
break;
}
}
}

} else if (id == ID_EQCREATURE_L) { // L for lefthand
Model *m = static_cast<Model*>(canvas->root->model);
if (!m)
m = static_cast<Model*>(canvas->model);

// make sure m is a valid pointer to a model
if (m) {
// This is an error check to make sure the creature can be equipped.
for(int k=0; k<m->ATT_MAX; k++){
if (m->attLookup[k] == PS_LEFT_PALM) {
SelectCreatureItem(CS_HAND_LEFT, 0, charControl, canvas);
break;
}
}
}
} else if (id==ID_SHADER_DEATH) {
//Shader test("Shaders\\Pixel\\FFXDeath.bls");
//test.Load();
}
}

Vec3D ModelViewer::DoSetColor(const Vec3D &defColor)
{
wxColourData data;
wxColour dcol((unsigned char)(defColor.x*255.0f), (unsigned char)(defColor.y*255.0f), (unsigned char)(defColor.z*255.0f));
data.SetChooseFull(true);
data.SetColour(dcol);

wxColourDialog dialog(this, &data);

if (dialog.ShowModal() == wxID_OK) {
wxColour col = dialog.GetColourData().GetColour();
return Vec3D(col.Red()/255.0f, col.Green()/255.0f, col.Blue()/255.0f);
}
return defColor;
}

void ModelViewer::OnSetEquipment(wxCommandEvent &event)
{
if (isChar)
charControl->OnButton(event);

UpdateControls();
}

void ModelViewer::OnCharToggle(wxCommandEvent &event)
{
if (event.GetId() == ID_VIEW_NPC)
charControl->selectNPC(UPDATE_NPC);
if (event.GetId() == ID_VIEW_ITEM)
charControl->selectItem(UPDATE_SINGLE_ITEM, -1, -1);
else if (isChar)
charControl->OnCheck(event);

}

void ModelViewer::OnMount(wxCommandEvent &event)
{
/*
const unsigned int mountSlot = 0;

// check if it's mountable
if (!canvas->viewingModel) return;
Model *root = (Model*)canvas->root->model;
if (!root) return;
if (root->name.substr(0,8)!="Creature") return;
bool mountable = (root->header.nAttachLookup > mountSlot) && (root->attLookup[mountSlot]!=-1);
if (!mountable) return;

std::string fn = charControl->selectCharModel();
if (fn.length()==0) return;

canvas->root->delChildren();
Attachment *att = canvas->root->addChild(fn.c_str(), mountSlot, -1);

wxHostInfo hi;
hi = layoutManager->GetDockHost(wxDEFAULT_RIGHT_HOST);
if (!charControlDockWindow->IsDocked()) {
layoutManager->DockWindow(charControlDockWindow, hi);
charControlDockWindow->Show(TRUE);
}
charMenu->Check(ID_SHOW_UNDERWEAR, true);
charMenu->Check(ID_SHOW_EARS, true);
charMenu->Check(ID_SHOW_HAIR, true);
charMenu->Check(ID_SHOW_FACIALHAIR, true);

Model *m = (Model*)att->model;
charControl->UpdateModel(att);

menuBar->EnableTop(2, true);
isChar = true;

// find a Mount animation (id = 91, let's hope this doesn't change)
for (size_t i=0; i<m->header.nAnimations; i++) {
if (m->anims[i].animID == 91) {
m->currentAnim = (int)i;
break;
}
}
*/

charControl->selectMount();
}

void ModelViewer::OnSave(wxCommandEvent &event)
{
static wxFileName dir = cfgPath;

if (!canvas || (!canvas->model && !canvas->wmo))
return;

if (event.GetId() == ID_FILE_SCREENSHOT) {
wxString tmp = _T("screenshot_");
tmp << ssCounter;
wxFileDialog dialog(this, _("Save screenshot"), dir.GetPath(wxPATH_GET_VOLUME), tmp, _T("Bitmap Images (*.bmp)|*.bmp|TGA Images (*.tga)|*.tga|JPEG Images (*.jpg)|*.jpg|PNG Images (*.png)|*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
dialog.SetFilterIndex(imgFormat);

if (dialog.ShowModal()==wxID_OK) {
imgFormat = dialog.GetFilterIndex();
tmp = dialog.GetPath();
dialog.Show(false);
canvas->Screenshot(tmp);
dir.SetPath(tmp);
ssCounter++;
}

//canvas->InitView();

} else if (event.GetId() == ID_FILE_EXPORTGIF) {
if (canvas->wmo)
return;

if (!canvas->model)
return;

if (!video.supportFBO && !video.supportPBO) {
wxMessageBox(_T("This function is currently disabled for video cards that don't\nsupport the FrameBufferObject or PixelBufferObject OpenGL extensions"), _T("Error"));
return;
}

wxFileDialog dialog(this, _T("Save Animation"), dir.GetPath(wxPATH_GET_VOLUME), _T("filename"), _T("Animation"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition);

if (dialog.ShowModal()==wxID_OK) {
// Save the folder location for next time
dir.SetPath(dialog.GetPath());

// Show our exporter window
animExporter->Init(dialog.GetPath());
animExporter->Show(true);
}

} else if (event.GetId() == ID_FILE_EXPORTAVI) {
if (canvas->wmo && !canvas->model)
return;

if (!video.supportFBO && !video.supportPBO) {
wxMessageBox(_T("This function is currently disabled for video cards that don't\nsupport the FrameBufferObject or PixelBufferObject OpenGL extensions"), _T("Error"));
return;
}

wxFileDialog dialog(this, _T("Save AVI"), dir.GetPath(wxPATH_GET_VOLUME), _T("animation.avi"), _T("animation (*.avi)|*.avi"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition);

if (dialog.ShowModal()==wxID_OK) {
animExporter->CreateAvi(dialog.GetPath());
}

} else if (event.GetId() == ID_FILE_SCREENSHOTCONFIG) {
if (!imageControl) {
imageControl = new ImageControl(this, ID_IMAGE_FRAME, canvas);

interfaceManager.AddPane(imageControl, wxAuiPaneInfo().
Name(wxT("Screenshot")).Caption(_("Screenshot")).
FloatingSize(wxSize(295,145)).Float().Fixed().
Dockable(false)); //.FloatingPosition(GetStartPosition())
}

imageControl->OnShow(&interfaceManager);
}
}

void ModelViewer::OnBackground(wxCommandEvent &event)
{
static wxFileName dir = cfgPath;

int id = event.GetId();

if (id == ID_BACKGROUND) {
if (event.IsChecked()) {
wxFileDialog dialog(this, _("Load Background"), dir.GetPath(wxPATH_GET_VOLUME), wxEmptyString, _("Bitmap Images (*.bmp)|*.bmp|TGA Images (*.tga)|*.tga|Jpeg Images (*.jpg)|*.jpg|PNG Images (*.png)|*.png|AVI Video file(*.avi)|*.avi"));
if (dialog.ShowModal() == wxID_OK) {
canvas->LoadBackground(dialog.GetPath());
dir.SetPath(dialog.GetPath());
viewMenu->Check(ID_BACKGROUND, canvas->drawBackground);
} else {
viewMenu->Check(ID_BACKGROUND, false);
}
} else {
canvas->drawBackground = false;
}
} else if (id == ID_SKYBOX) {
if (canvas->skyModel) {
wxDELETE(canvas->skyModel);
canvas->sky->delChildren();

} else {
// List of skybox models, LightSkybox.dbc
/*
const wxString skyboxes[] = {
"Environments\\Stars\\Aurora.m2",
"Environments\\Stars\\AuroraOrange.m2",
"Environments\\Stars\\AuroraYellowGreen.m2",
"Environments\\Stars\\AzjolNerub_SkyA.m2",
"Environments\\Stars\\Battlefield_Dirty_SkyBox.m2",
"Environments\\Stars\\BladesEdgeForestSkybox.m2",
"Environments\\Stars\\BladesEdgeNightelfSkybox.m2",
"Environments\\Stars\\BladesEdgeSkybox.m2",
"Environments\\Stars\\BonewasteSkybox.m2",
"Environments\\Stars\\COT_sky01.m2",
"Environments\\Stars\\CavernsOfTimeSky.m2",
"Environments\\Stars\\ChamberAspectsBlackSky.m2",
"Environments\\Stars\\ColdarraSky.m2",
"Environments\\Stars\\DalaranSkyBox.m2",
"Environments\\Stars\\DeathClouds.m2",
"Environments\\Stars\\DeathKnightFireSkyBox.m2",
"Environments\\Stars\\DeathSkybox.m2",
"Environments\\Stars\\DireMaulSkybox.m2",
"Environments\\Stars\\DragonblightScarletSkyBox.m2",
"Environments\\Stars\\HellfireSkybox.m2",
"Environments\\Stars\\IceCrownCitadelSky.m2",
"Environments\\Stars\\IceCrownDarkSky.m2",
"Environments\\Stars\\IceCrownScourgeSky.m2",
"Environments\\Stars\\IceCrownSky.m2",
"Environments\\Stars\\IceCrownSunsetSky.m2",
"Environments\\Stars\\NagrandSkyBox.m2",
"Environments\\Stars\\NetherstormSkybox.m2",
"Environments\\Stars\\NagrandSkybox.m2",
"Environments\\Stars\\NexusRaid_NebulaSky.m2",
"Environments\\Stars\\NexusRaid_RuneEffects_Nebula.m2",
"Environments\\Stars\\NexusRaid_RuneEffects_Starry.m2",
"Environments\\Stars\\NexusRaid_StarrySky.m2",
"Environments\\Stars\\NexusRaid_Wormhole.m2",
"Environments\\Stars\\PortalWorldLegionSky.m2",
"Environments\\Stars\\ShadowmoonIllidan.m2",
"Environments\\Stars\\ShadowmoonSkybox.m2",
"Environments\\Stars\\Stars.m2",
"Environments\\Stars\\StormPeaks_SkyA.m2",
"Environments\\Stars\\StormPeaks_SkyB_Storm.m2",
"Environments\\Stars\\StormPeaks_SkyC_Ulduar.m2",
"Environments\\Stars\\StratholmeSkybox.m2",
"Environments\\Stars\\UlduranCloudySky.m2",
"Environments\\Stars\\WintergraspSmokySky.m2",
"Environments\\Stars\\ZulDrakSkyA.m2",
"Environments\\Stars\\ZulDrakSkyB.m2",
"World\\Outland\\PassiveDoodads\\SkyBox\\OutlandSkyBox.m2"
};*/
wxArrayString skyboxes;

for (LightSkyBoxDB::Iterator it=skyboxdb.begin(); it!=skyboxdb.end(); ++it) {
wxString str(it->getString(LightSkyBoxDB::Name));
str = str.BeforeLast('.');
str.Append(_T(".m2"));

if (skyboxes.Index(str, false) == wxNOT_FOUND)
skyboxes.Add(str);
}
skyboxes.Add(_T("World\\Outland\\PassiveDoodads\\SkyBox\\OutlandSkyBox.m2"));
skyboxes.Sort();


wxSingleChoiceDialog skyDialog(this, _("Choose"), _("Select a Sky Box"), skyboxes);
if (skyDialog.ShowModal() == wxID_OK && skyDialog.GetStringSelection() != _T("")) {
canvas->skyModel = new Model(std::string(skyDialog.GetStringSelection().mb_str()), false);
canvas->sky->model = canvas->skyModel;
}
}

canvas->drawSky = event.IsChecked();
}
}

void ModelViewer::SaveChar(const char *fn)
{
ofstream f(fn, ios_base::out|ios_base::trunc);
f << canvas->model->name << endl;
f << charControl->cd.race << " " << charControl->cd.gender << endl;
f << charControl->cd.skinColor << " " << charControl->cd.faceType << " " << charControl->cd.hairColor << " " << charControl->cd.hairStyle << " " << charControl->cd.facialHair << " " << charControl->cd.facialColor << endl;
for (int i=0; i<NUM_CHAR_SLOTS; i++) {
f << charControl->cd.equipment[i] << endl;
}

// 5976 is the ID value for "Guild Tabard"
if (charControl->cd.equipment[CS_TABARD] == 5976) {
f << charControl->td.Background << " " << charControl->td.Border << " " << charControl->td.BorderColor << " " << charControl->td.Icon << " " << charControl->td.IconColor << endl;
}

f << endl;
f.close();
}

void ModelViewer::LoadChar(const char *fn)
{
std::string modelname;
ifstream f(fn);

f >> modelname; // model name

// Clear the existing model
if (isWMO) {
//canvas->clearAttachments();
wxDELETE(canvas->wmo);
canvas->wmo = NULL;
} else {
canvas->clearAttachments();
//if (!isChar) // may memory leak
// wxDELETE(canvas->model);
canvas->model = NULL;
}

// Load the model
LoadModel(wxString(modelname.c_str(), wxConvUTF8));
canvas->model->modelType = MT_CHAR;

f >> charControl->cd.race >> charControl->cd.gender; // race and gender
f >> charControl->cd.skinColor >> charControl->cd.faceType >> charControl->cd.hairColor >> charControl->cd.hairStyle >> charControl->cd.facialHair >> charControl->cd.facialColor;

while (!f.eof()) {
for (int i=0; i<NUM_CHAR_SLOTS; i++) {
f >> charControl->cd.equipment[i];
}
break;
}

// 5976 is the ID value for "Guild Tabard"
if (charControl->cd.equipment[CS_TABARD] == 5976 && !f.eof()) {
f >> charControl->td.Background >> charControl->td.Border >> charControl->td.BorderColor >> charControl->td.Icon >> charControl->td.IconColor;
charControl->td.showCustom = true;
}

f.close();

charControl->RefreshModel();
charControl->RefreshEquipment();

charMenu->Enable(ID_SAVE_CHAR, true);
charMenu->Enable(ID_SHOW_UNDERWEAR, true);
charMenu->Enable(ID_SHOW_EARS, true);
charMenu->Enable(ID_SHOW_HAIR, true);
charMenu->Enable(ID_SHOW_FACIALHAIR, true);
charMenu->Enable(ID_SHOW_FEET, true);
charMenu->Enable(ID_SHEATHE, true);
charMenu->Enable(ID_SAVE_EQUIPMENT, true);
charMenu->Enable(ID_LOAD_EQUIPMENT, true);
charMenu->Enable(ID_CLEAR_EQUIPMENT, true);
charMenu->Enable(ID_LOAD_SET, true);
charMenu->Enable(ID_LOAD_START, true);
charMenu->Enable(ID_LOAD_NPC_START, true);
charMenu->Enable(ID_MOUNT_CHARACTER, true);
charMenu->Enable(ID_CHAR_RANDOMISE, true);

// Update interface docking components
interfaceManager.Update();
}

void ModelViewer::OnLanguage(wxCommandEvent &event)
{
if (event.GetId() == ID_LANGUAGE) {
/*
static const wxLanguage langIds[] =
{
wxLANGUAGE_ENGLISH,
wxLANGUAGE_KOREAN,
wxLANGUAGE_FRENCH,
wxLANGUAGE_GERMAN,
wxLANGUAGE_CHINESE_SIMPLIFIED,
wxLANGUAGE_CHINESE_TRADITIONAL,
wxLANGUAGE_SPANISH,
};
*/

wxString langNames[] =
{
_T("English"),
_T("Korean"),
_T("French"),
_T("German"),
_T("Chinese (Simplified)"),
_T("Chinese (Traditional)"),
_T("Spanish"),
};

// the arrays should be in sync
//wxCOMPILE_TIME_ASSERT(WXSIZEOF(langNames) == WXSIZEOF(langIds), LangArraysMismatch);

long lng = wxGetSingleChoiceIndex(_("Please select a language:"), _("Language"), WXSIZEOF(langNames), langNames);

if (lng != -1) {
interfaceID = lng;
wxMessageBox(_T("You will need to reload WoW Model Viewer for changes to take effect."), _T("Language Changed"), wxOK | wxICON_INFORMATION);
}
}
}

void ModelViewer::OnAbout(wxCommandEvent &event)
{
/*
text = new wxStaticText(this, wxID_ANY, _T("Developers: UfoZ, Darjk\n\n\
Pioneers: UfoZ, Linghuye, nSzAbolcs\n\n\
Translators: Culhag (French), Die_Backe (Deutsch)\n\n\
Developed Using:\n\
wxWidgets(2.6.3), wxAUI(0.9.2), OpenGL, zlib,\n\
CxImage(5.99c), MPQLib, DDSLib, GLEW(1.3.3)\n\n\
Build Info:\nVersion 0.5 compiled using Visual C++ 7.1 (2003) for\n\
Windows 98\\ME\\2000\\XP on 17th December 2006\n\n\
*/

wxAboutDialogInfo info;
info.SetName(APP_TITLE);
info.SetVersion(APP_VERSION _T(" ") APP_PLATFORM);
info.AddDeveloper(_T("Ufo_Z"));
info.AddDeveloper(_T("Darjk"));
info.AddDeveloper(_T("Chuanhsing"));
info.AddDeveloper(_T("Kjasi (A.K.A. Sephiroth3D)"));
info.AddDeveloper(_T("Tob.Franke"));
info.AddTranslator(_T("MadSquirrel (French)"));
info.AddTranslator(_T("Tigurius (Deutsch)"));
info.AddTranslator(_T("Kurax (Chinese)"));

info.SetWebSite(_T("http://www.wowmodelviewer.org/"));
info.SetCopyright(
wxString(_T("World of Warcraft(R) is a Registered trademark of\n\
Blizzard Entertainment(R). All game assets and content\n\
is (C)2006 Blizzard Entertainment(R). All rights reserved.")));

info.SetLicence(_T("WoWmodelview is released under the GNU General Public License."));

info.SetDescription(_T("WoWmodelview is a 3D model viewer for World of Warcraft.\nIt uses the data files included with the game to display\nthe 3D models from the game: creatures, characters, spell\neffects, objects and so forth.\n\nCredits To: Linghuye, nSzAbolcs, Sailesh, Terran and Cryect\nfor their contributions either directly or indirectly."));
//info.SetArtists();
//info.SetDocWriters();

wxIcon icon("mainicon",wxBITMAP_TYPE_ICO_RESOURCE,128,128);
#ifndef _WINDOWS
#if defined (_LINUX)
icon.LoadFile(../bin_support/icon/wmv_xpm);
#elif defined (_MAC)
//icon.LoadFile(../bin_support/icon/wmv.icns);
#endif
#endif
icon.SetHeight(128);
icon.SetWidth(128);
info.SetIcon(icon);

#ifndef __WXMAC__
// FIXME: Doesn't link on OSX
wxAboutBox(info);
#endif
}

void ModelViewer::OnCheckForUpdate(wxCommandEvent &event)
{
wxURL url(_T("http://wowmodelviewer.googlecode.com/svn/trunk/latest.txt"));

if(url.GetError() == wxURL_NOERR) {
wxInputStream *stream = url.GetInputStream();

// here, just for example, I read 1024 bytes. You should read what you need...
char buffer[1024];
stream->Read(&buffer, 1024);

// Sort the data
wxString data(wxString(buffer, wxConvUTF8));
wxString version = data.BeforeFirst(10);
wxString downloadURL = data.AfterLast(10);
int Compare = version.find(wxString(APP_VERSION));
#ifdef _DEBUG
wxLogMessage("Update Data:\nCurrent Version: \"%s\"\nRecorded Version \"%s\"\nURL Download: \"%s\"\nComparison Result: %i",wxString(APP_VERSION), version, downloadURL, Compare);
#endif

if (Compare == 0) {
wxMessageBox(_T("You have the most up-to-date version."), _T("Update Check"));
} else {
wxString msg = _T("The most current version is: ");
msg.Append(version);
msg.Append(_T("\nWould you like to goto the download page?"));
int answer = wxMessageBox(msg, _("Update Check"), wxYES_NO, this);
if (answer == wxYES)
wxLaunchDefaultBrowser(wxString(downloadURL.ToUTF8(), wxConvUTF8));
}

// Create a string from the data that was received... (?)
//wxString webversion;
//wxMessageBox(wxString::Format("%s",buffer));

delete stream;
}else{
wxMessageBox(_T("Error retrieving update information."),_T("Update Error"));
}
}

void ModelViewer::OnCanvasSize(wxCommandEvent &event)
{
int id = event.GetId();
unsigned int sizex = 0;
unsigned int sizey = 0;

if (id == ID_CANVAS512) {
sizex = 512;
sizey = 512;
} else if (id == ID_CANVAS640) {
sizex = 640;
sizey = 480;
} else if (id == ID_CANVAS800) {
sizex = 800;
sizey = 600;
} else if (id == ID_CANVAS1024) {
sizex = 1024;
sizey = 768;
} else if (id == ID_CANVAS1152) {
sizex = 1152;
sizey = 864;
} else if (id == ID_CANVAS1280) {
sizex = 1280;
sizey = 768;
} else if (id == ID_CANVAS120) {
sizex = 120;
sizey = 120;
} else if (id == ID_CANVAS1600) {
sizex = 1600;
sizey = 1200;
} else if (id == ID_CANVASW720) {
sizex = 1280;
sizey = 720;
} else if (id == ID_CANVASW1080) {
sizex = 1920;
sizey = 1080;
} else if (id == ID_CANVASW1200) {
sizex = 1900;
sizey = 1200;
}

if (sizex > 0 && sizey > 0) {
int curx=0, cury=0;
int difx=0, dify=0;

canvas->GetClientSize(&curx, &cury);
difx = sizex - curx;
dify = sizey - cury;
// if the window is already large enough, just shrink the canvas
//if (difx <= 0 && dify <= 0 && sizex < 800 && sizey < 600) {
// canvas->SetClientSize(sizex, sizey);
//} else {
GetClientSize(&curx, &cury);
SetSize((curx + difx), (cury + dify));
//}
}
}

void ModelViewer::ModelInfo()
{
if (!canvas->model)
return;
Model *m = canvas->model;
const char *fn="ModelInfo.xml";
ofstream xml(fn, ios_base::out | ios_base::trunc);

if (!xml.is_open()) {
wxLogMessage(_T("Error: Unable to open file '%s'. Could not export model."), fn);
return;
}

MPQFile f(m->modelname.c_str());
if (f.isEof() || (f.getSize() < sizeof(ModelHeader))) {
wxLogMessage(_T("Error: Unable to load model: [%s]"), m->modelname.c_str());
// delete this; //?
xml.close();
f.close();
return;
}

MPQFile g(m->lodname.c_str());
if (g.isEof() || (g.getSize() < sizeof(ModelView))) {
wxLogMessage(_T("Error: Unable to load Lod: [%s]"), m->lodname.c_str());
// delete this; //?
xml.close();
f.close();
g.close();
return;
}
ModelView *view = (ModelView*)(g.getBuffer());

xml << "<m2>" << endl;
xml << " <info>" << endl;
xml << " <fullname>" <<m->fullname << "</fullname>" << endl;
xml << " <modelname>" <<m->modelname << "</modelname>" << endl;
xml << " </info>" << endl;
xml << " <header>" << endl;
// xml << " <id>" << m->header.id << "</id>" << endl;
xml << " <nameLength>" << m->header.nameLength << "</nameLength>" << endl;
xml << " <nameOfs>" << m->header.nameOfs << "</nameOfs>" << endl;
xml << " <name>" << f.getBuffer()+m->header.nameOfs << "</name>" << endl;
xml << " <GlobalModelFlags>" << m->header.GlobalModelFlags << "</GlobalModelFlags>" << endl;
xml << " <nGlobalSequences>" << m->header.nGlobalSequences << "</nGlobalSequences>" << endl;
xml << " <ofsGlobalSequences>" << m->header.ofsGlobalSequences << "</ofsGlobalSequences>" << endl;
xml << " <nAnimations>" << m->header.nAnimations << "</nAnimations>" << endl;
xml << " <ofsAnimations>" << m->header.ofsAnimations << "</ofsAnimations>" << endl;
xml << " <nAnimationLookup>" << m->header.nAnimationLookup << "</nAnimationLookup>" << endl;
xml << " <ofsAnimationLookup>" << m->header.ofsAnimationLookup << "</ofsAnimationLookup>" << endl;
xml << " <nBones>" << m->header.nBones << "</nBones>" << endl;
xml << " <ofsBones>" << m->header.ofsBones << "</ofsBones>" << endl;
xml << " <nKeyBoneLookup>" << m->header.nKeyBoneLookup << "</nKeyBoneLookup>" << endl;
xml << " <ofsKeyBoneLookup>" << m->header.ofsKeyBoneLookup << "</ofsKeyBoneLookup>" << endl;
xml << " <nVertices>" << m->header.nVertices << "</nVertices>" << endl;
xml << " <ofsVertices>" << m->header.ofsVertices << "</ofsVertices>" << endl;
xml << " <nViews>" << m->header.nViews << "</nViews>" << endl;
xml << " <lodname>" <<m->lodname << "</lodname>" << endl;
xml << " <nColors>" << m->header.nColors << "</nColors>" << endl;
xml << " <ofsColors>" << m->header.ofsColors << "</ofsColors>" << endl;
xml << " <nTextures>" << m->header.nTextures << "</nTextures>" << endl;
xml << " <ofsTextures>" << m->header.ofsTextures << "</ofsTextures>" << endl;
xml << " <nTransparency>" << m->header.nTransparency << "</nTransparency>" << endl;
xml << " <ofsTransparency>" << m->header.ofsTransparency << "</ofsTransparency>" << endl;
xml << " <nTexAnims>" << m->header.nTexAnims << "</nTexAnims>" << endl;
xml << " <ofsTexAnims>" << m->header.ofsTexAnims << "</ofsTexAnims>" << endl;
xml << " <nTexReplace>" << m->header.nTexReplace << "</nTexReplace>" << endl;
xml << " <ofsTexReplace>" << m->header.ofsTexReplace << "</ofsTexReplace>" << endl;
xml << " <nTexFlags>" << m->header.nTexFlags << "</nTexFlags>" << endl;
xml << " <ofsTexFlags>" << m->header.ofsTexFlags << "</ofsTexFlags>" << endl;
xml << " <nBoneLookup>" << m->header.nBoneLookup << "</nBoneLookup>" << endl;
xml << " <ofsBoneLookup>" << m->header.ofsBoneLookup << "</ofsBoneLookup>" << endl;
xml << " <nTexLookup>" << m->header.nTexLookup << "</nTexLookup>" << endl;
xml << " <ofsTexLookup>" << m->header.ofsTexLookup << "</ofsTexLookup>" << endl;
xml << " <nTexUnitLookup>" << m->header.nTexUnitLookup << "</nTexUnitLookup>" << endl;
xml << " <ofsTexUnitLookup>" << m->header.ofsTexUnitLookup << "</ofsTexUnitLookup>" << endl;
xml << " <nTransparencyLookup>" << m->header.nTransparencyLookup << "</nTransparencyLookup>" << endl;
xml << " <ofsTransparencyLookup>" << m->header.ofsTransparencyLookup << "</ofsTransparencyLookup>" << endl;
xml << " <nTexAnimLookup>" << m->header.nTexAnimLookup << "</nTexAnimLookup>" << endl;
xml << " <ofsTexAnimLookup>" << m->header.ofsTexAnimLookup << "</ofsTexAnimLookup>" << endl;
xml << " <PhysicsSettings>" << endl;
xml << " <VertexBox0>" << m->header.ps.VertexBox[0] << "</VertexBox0>" << endl;
xml << " <VertexBox1>" << m->header.ps.VertexBox[1] << "</VertexBox1>" << endl;
xml << " <VertexRadius>" << m->header.ps.VertexRadius << "</VertexRadius>" << endl;
xml << " <BoundingBox0>" << m->header.ps.BoundingBox[0] << "</BoundingBox0>" << endl;
xml << " <BoundingBox1>" << m->header.ps.BoundingBox[1] << "</BoundingBox1>" << endl;
xml << " <BoundingRadius>" << m->header.ps.BoundingRadius << "</BoundingRadius>" << endl;
xml << " </PhysicsSettings>" << endl;
xml << " <nBoundingTriangles>" << m->header.nBoundingTriangles << "</nBoundingTriangles>" << endl;
xml << " <ofsBoundingTriangles>" << m->header.ofsBoundingTriangles << "</ofsBoundingTriangles>" << endl;
xml << " <nBoundingVertices>" << m->header.nBoundingVertices << "</nBoundingVertices>" << endl;
xml << " <ofsBoundingVertices>" << m->header.ofsBoundingVertices << "</ofsBoundingVertices>" << endl;
xml << " <nBoundingNormals>" << m->header.nBoundingNormals << "</nBoundingNormals>" << endl;
xml << " <ofsBoundingNormals>" << m->header.ofsBoundingNormals << "</ofsBoundingNormals>" << endl;
xml << " <nAttachments>" << m->header.nAttachments << "</nAttachments>" << endl;
xml << " <ofsAttachments>" << m->header.ofsAttachments << "</ofsAttachments>" << endl;
xml << " <nAttachLookup>" << m->header.nAttachLookup << "</nAttachLookup>" << endl;
xml << " <ofsAttachLookup>" << m->header.ofsAttachLookup << "</ofsAttachLookup>" << endl;
xml << " <nEvents>" << m->header.nEvents << "</nEvents>" << endl;
xml << " <ofsEvents>" << m->header.ofsEvents << "</ofsEvents>" << endl;
xml << " <nLights>" << m->header.nLights << "</nLights>" << endl;
xml << " <ofsLights>" << m->header.ofsLights << "</ofsLights>" << endl;
xml << " <nCameras>" << m->header.nCameras << "</nCameras>" << endl;
xml << " <ofsCameras>" << m->header.ofsCameras << "</ofsCameras>" << endl;
xml << " <nCameraLookup>" << m->header.nCameraLookup << "</nCameraLookup>" << endl;
xml << " <ofsCameraLookup>" << m->header.ofsCameraLookup << "</ofsCameraLookup>" << endl;
xml << " <nRibbonEmitters>" << m->header.nRibbonEmitters << "</nRibbonEmitters>" << endl;
xml << " <ofsRibbonEmitters>" << m->header.ofsRibbonEmitters << "</ofsRibbonEmitters>" << endl;
xml << " <nParticleEmitters>" << m->header.nParticleEmitters << "</nParticleEmitters>" << endl;
xml << " <ofsParticleEmitters>" << m->header.ofsParticleEmitters << "</ofsParticleEmitters>" << endl;
xml << " </header>" << endl;

xml << " <SkeletonAndAnimation>" << endl;

xml << " <GlobalSequences>" << endl;
for(size_t i=0; i<m->header.nGlobalSequences; i++)
xml << "<Sequence>" << m->globalSequences[i] << "</Sequence>" << endl;
xml << " </GlobalSequences>" << endl;

xml << " <Animations>" << endl;
for(size_t i=0; i<m->header.nAnimations; i++) {
xml << " <Animation id=\"" << i << "\">" << endl;
xml << " <animID>"<< m->anims[i].animID << "</animID>" << endl;
// subAnimID
xml << " <length>"<< m->anims[i].timeEnd << "</length>" << endl;
xml << " <moveSpeed>"<< m->anims[i].moveSpeed << "</moveSpeed>" << endl;
xml << " <flags>"<< m->anims[i].flags << "</flags>" << endl;
xml << " <probability>"<< m->anims[i].probability << "</probability>" << endl;
xml << " <d1>"<< m->anims[i].d1 << "</d1>" << endl;
xml << " <d2>"<< m->anims[i].d2 << "</d2>" << endl;
xml << " <playSpeed>"<< m->anims[i].playSpeed << "</playSpeed>" << endl;
xml << " <boxA>"<< m->anims[i].boxA << "</boxA>" << endl;
xml << " <boxB>"<< m->anims[i].boxB << "</boxB>" << endl;
xml << " <rad>"<< m->anims[i].rad << "</rad>" << endl;
xml << " <NextAnimation>"<< m->anims[i].NextAnimation << "</NextAnimation>" << endl;
xml << " <Index>"<< m->anims[i].Index << "</Index>" << endl;
xml << " </Animation>" << endl;

}
xml << " </Animations>" << endl;

xml << " <AnimationLookups>" << endl;
for(size_t i=0; i<m->header.nAnimationLookup; i++)
xml << " <AnimationLookup id=\"" << i << "\">" << m->animLookups[i] << "</AnimationLookup>" << endl;
xml << " </AnimationLookups>" << endl;

xml << " <Bones>" << endl;
for(size_t i=0; i<m->header.nBones; i++) {
xml << " <Bone id=\"" << i << "\">" << endl;
xml << " <keyboneid>"<< m->bones[i].boneDef.keyboneid << "</keyboneid>" << endl;
xml << " <billboard>"<< m->bones[i].billboard << "</billboard>" << endl;
xml << " <parent>"<< m->bones[i].boneDef.parent << "</parent>" << endl;
xml << " <geoid>"<< m->bones[i].boneDef.geoid << "</geoid>" << endl;
xml << " <unknown>"<< m->bones[i].boneDef.unknown << "</unknown>" << endl;
#if 0 // too huge
// AB translation
xml << " <trans>" << endl;
xml << m->bones[i].trans;
xml << " </trans>" << endl;
// AB rotation
xml << " <rot>" << endl;
xml << m->bones[i].rot;
xml << " </rot>" << endl;
// AB scaling
xml << " <scale>" << endl;
xml << m->bones[i].scale;
xml << " </scale>" << endl;
#endif
xml << " <pivot>"<< m->bones[i].boneDef.pivot << "</pivot>" << endl;
xml << " </Bone>" << endl;
}
xml << " </Bones>" << endl;

xml << " <BoneLookups></BoneLookups>" << endl;

xml << " <KeyBoneLookups>" << endl;
for(size_t i=0; i<m->header.nKeyBoneLookup; i++)
xml << "<KeyBoneLookup id=\"" << i << "\">" << m->keyBoneLookup[i] << "</KeyBoneLookup>" << endl;
xml << " </KeyBoneLookups>" << endl;

xml << " </SkeletonAndAnimation>" << endl;

xml << " <GeometryAndRendering>" << endl;

xml << " <Vertices>" << m->header.nVertices << "</Vertices>" << endl;
xml << " <Views>" << endl;

xml << " <Indices>" << view->nIndex << "</Indices>" << endl;
xml << " <Triangles>" << view->nTris << "</Triangles>" << endl;
xml << " <Properties>" << view->nProps << "</Properties>" << endl;
xml << " <Subs>" << view->nSub << "</Subs>" << endl;
xml << " <Texs>" << view->nTex << "</Texs>" << endl;


xml << " <RenderPasses>" << endl;
for (size_t i=0; i<m->passes.size(); i++) {
xml << " <RenderPass id=\"" << i << "\">" << endl;
ModelRenderPass &p = m->passes[i];
xml << " <indexStart>" << p.indexStart << "</indexStart>" << endl;
xml << " <indexCount>" << p.indexCount << "</indexCount>" << endl;
xml << " <vertexStart>" << p.vertexStart << "</vertexStart>" << endl;
xml << " <vertexEnd>" << p.vertexEnd << "</vertexEnd>" << endl;
xml << " <tex>" << p.tex << "</tex>" << endl;
xml << " <useTex2>" << p.useTex2 << "</useTex2>" << endl;
xml << " <useEnvMap>" << p.useEnvMap << "</useEnvMap>" << endl;
xml << " <cull>" << p.cull << "</cull>" << endl;
xml << " <trans>" << p.trans << "</trans>" << endl;
xml << " <unlit>" << p.unlit << "</unlit>" << endl;
xml << " <noZWrite>" << p.noZWrite << "</noZWrite>" << endl;
xml << " <billboard>" << p.billboard << "</billboard>" << endl;
xml << " <p>" << p.p << "</p>" << endl;
xml << " <texanim>" << p.texanim << "</texanim>" << endl;
xml << " <color>" << p.color << "</color>" << endl;
xml << " <opacity>" << p.opacity << "</opacity>" << endl;
xml << " <blendmode>" << p.blendmode << "</blendmode>" << endl;
xml << " <order>" << p.order << "</order>" << endl;
xml << " <geoset>" << p.geoset << "</geoset>" << endl;
xml << " <swrap>" << p.swrap << "</swrap>" << endl;
xml << " <twrap>" << p.twrap << "</twrap>" << endl;
xml << " <ocol>" << p.ocol << "</ocol>" << endl;
xml << " <ecol>" << p.ecol << "</ecol>" << endl;
xml << " </RenderPass>" << endl;
}
xml << " </RenderPasses>" << endl;

xml << " <Geosets>" << endl;
for (size_t i=0; i<m->geosets.size(); i++) {
xml << " <Geoset id=\"" << i << "\">" << endl;
xml << " <id>" << m->geosets[i].id << "</id>" << endl;
xml << " <vstart>" << m->geosets[i].vstart << "</vstart>" << endl;
xml << " <vcount>" << m->geosets[i].vcount << "</vcount>" << endl;
xml << " <istart>" << m->geosets[i].istart << "</istart>" << endl;
xml << " <icount>" << m->geosets[i].icount << "</icount>" << endl;
xml << " <nBones>" << m->geosets[i].nBones << "</nBones>" << endl;
xml << " <StartBones>" << m->geosets[i].StartBones << "</StartBones>" << endl;
xml << " <BoundingBox>" << m->geosets[i].BoundingBox[0] << "</BoundingBox>" << endl;
xml << " <BoundingBox>" << m->geosets[i].BoundingBox[1] << "</BoundingBox>" << endl;
xml << " <radius>" << m->geosets[i].radius << "</radius>" << endl;
xml << " </Geoset>" << endl;
}
xml << " </Geosets>" << endl;

ModelTexUnit *tex = (ModelTexUnit*)(g.getBuffer() + view->ofsTex);
xml << " <TexUnits>" << endl;
for (size_t i=0; i<view->nTex; i++) {
xml << " <TexUnit id=\"" << i << "\">" << endl;
xml << " <flags>" << tex[i].flags << "</flags>" << endl;
xml << " <shading>" << tex[i].shading << "</shading>" << endl;
xml << " <op>" << tex[i].op << "</op>" << endl;
xml << " <op2>" << tex[i].op2 << "</op2>" << endl;
xml << " <colorIndex>" << tex[i].colorIndex << "</colorIndex>" << endl;
xml << " <flagsIndex>" << tex[i].flagsIndex << "</flagsIndex>" << endl;
xml << " <texunit>" << tex[i].texunit << "</texunit>" << endl;
xml << " <mode>" << tex[i].mode << "</mode>" << endl;
xml << " <textureid>" << tex[i].textureid << "</textureid>" << endl;
xml << " <texunit2>" << tex[i].texunit2 << "</texunit2>" << endl;
xml << " <transid>" << tex[i].transid << "</transid>" << endl;
xml << " <texanimid>" << tex[i].texanimid << "</texanimid>" << endl;
xml << " </TexUnit>" << endl;
}
xml << " </TexUnits>" << endl;

xml << " </Views>" << endl;

xml << " <RenderFlags></RenderFlags>" << endl;

xml << " <Colors>" << endl;
for(size_t i=0; i<m->header.nColors; i++) {
xml << " <Color id=\"" << i << "\">" << endl;
// AB color
xml << " <color>" << endl;
xml << m->colors[i].color;
xml << " </color>" << endl;
// AB opacity
xml << " <opacity>" << endl;
xml << m->colors[i].opacity;
xml << " </opacity>" << endl;
xml << " </Color>" << endl;
}
xml << " </Colors>" << endl;

xml << " <Transparency>" << endl;
for(size_t i=0; i<m->header.nTransparency; i++) {
xml << " <Tran id=\"" << i << "\">" << endl;
// AB trans
xml << " <trans>" << endl;
xml << m->transparency[i].trans;
xml << " </trans>" << endl;
xml << " </Tran>" << endl;
}
xml << " </Transparency>" << endl;

xml << " <TransparencyLookup></TransparencyLookup>" << endl;

ModelTextureDef *texdef = (ModelTextureDef*)(f.getBuffer() + m->header.ofsTextures);
xml << " <Textures>" << endl;
for(size_t i=0; i<m->header.nTextures; i++) {
xml << " <Texture id=\"" << i << "\">" << endl;
xml << " <type>" << texdef[i].type << "</type>" << endl;
xml << " <flags>" << texdef[i].flags << "</flags>" << endl;
//xml << " <nameLen>" << texdef[i].nameLen << "</nameLen>" << endl;
//xml << " <nameOfs>" << texdef[i].nameOfs << "</nameOfs>" << endl;
if (texdef[i].type == TEXTURE_FILENAME)
xml << " <name>" << f.getBuffer()+texdef[i].nameOfs << "</name>" << endl;
xml << " </Texture>" << endl;
}
xml << " </Textures>" << endl;

xml << " <TextureLookup></TextureLookup>" << endl;
xml << " <ReplacableTextureLookup></ReplacableTextureLookup>" << endl;

xml << " </GeometryAndRendering>" << endl;

xml << " <Effects>" << endl;

xml << " <TexAnims>" << endl;
for(size_t i=0; i<m->header.nTexAnims; i++) {
xml << " <TexAnim id=\"" << i << "\">" << endl;
// AB trans
xml << " <trans>" << endl;
xml << m->texAnims[i].trans;
xml << " </trans>" << endl;
// AB rot
xml << " <rot>" << endl;
xml << m->texAnims[i].rot;
xml << " </rot>" << endl;
// AB scale
xml << " <scale>" << endl;
xml << m->texAnims[i].scale;
xml << " </scale>" << endl;
xml << " </TexAnim>" << endl;
}
xml << " </TexAnims>" << endl;

xml << " <RibbonEmitters></RibbonEmitters>" << endl;

xml << " <Particles>" << endl;
for (size_t i=0; i<m->header.nParticleEmitters; i++) {
xml << " <Particle id=\"" << i << "\">" << endl;
xml << m->particleSystems[i];
xml << " </Particle>" << endl;
}
xml << " </Particles>" << endl;

xml << " </Effects>" << endl;

xml << " <Miscellaneous>" << endl;

xml << " <BoundingVolumes></BoundingVolumes>" << endl;
xml << " <Lights></Lights>" << endl;
xml << " <Cameras></Cameras>" << endl;

xml << " <Attachments>" << endl;
for (size_t i=0; i<m->header.nAttachments; i++) {
xml << " <Attachment id=\"" << i << "\">" << endl;
xml << " <id>" << m->atts[i].id << "</id>" << endl;
xml << " <bone>" << m->atts[i].bone << "</bone>" << endl;
xml << " <pos>" << m->atts[i].pos << "</pos>" << endl;
xml << " </Attachment>" << endl;
}
xml << " </Attachments>" << endl;

xml << " <Events>" << endl;
for (size_t i=0; i<m->header.nEvents; i++) {
xml << " <Event id=\"" << i << "\">" << endl;
xml << m->events[i];
xml << " </Event>" << endl;
}
xml << " </Events>" << endl;


xml << " </Miscellaneous>" << endl;

// xml << " <>" << m->header. << "</>" << endl;
xml << "</m2>" << endl;
xml.close();
f.close();
g.close();
}

void DiscoveryNPC()
{
wxString name, ret;
// 1. from creaturedisplayinfo.dbc
for (CreatureSkinDB::Iterator it = skindb.begin(); it != skindb.end(); ++it) {
int npcid = it->getUInt(CreatureSkinDB::NPCID);
int id = it->getUInt(CreatureSkinDB::SkinID);
if (npcid == 0)
continue;
if (!npcs.avaiable(id)) {
name.Printf(_T("Skin%d"), id);
ret = npcs.addDiscoveryId(id, name);
}
}
// 2. from creaturedisplayinfoextra.dbc
}

void DiscoveryItem()
{
wxString name, ret;
items.cleanupDiscovery();
ofstream f(_T("discoveryitems.csv"), ios_base::out | ios_base::trunc);

// 1. from itemsets.dbc
for (ItemSetDB::Iterator it = setsdb.begin(); it != setsdb.end(); ++it) {
for(size_t i=0; i<ItemSetDB::NumItems; i++) {
int id;
if (gameVersion == 40000)
id = it->getUInt(ItemSetDB::ItemIDBaseV400+i);
else
id = it->getUInt(ItemSetDB::ItemIDBase+i);
if (id == 0)
continue;
if (!items.avaiable(id)) {
if (langID == 0)
name = it->getString(ItemSetDB::Name);
else
name.Printf(_T("Set%d"), it->getUInt(ItemSetDB::SetID));
ret = items.addDiscoveryId(id, name);
if (f.is_open() && ret != _T(""))
f << ret.mb_str() << endl;
}
}
}
// 2. from item.dbc
for (ItemDB::Iterator it = itemdb.begin(); it != itemdb.end(); ++it) {
int id = it->getUInt(ItemDB::ID);
if (!items.avaiable(id)) {
name.Printf(_T("Item%d"), id);
ret = items.addDiscoveryId(id, name);
if (f.is_open() && ret != _T(""))
f << ret.mb_str() << endl;
}
}
// 3. from creaturedisplayinfoextra.dbc
int slots[11] = {1, 3, 4, 5, 6, 7, 8, 9, 10, 19, 16};
for (NPCDB::Iterator it = npcdb.begin(); it != npcdb.end(); ++it) {
for(size_t i=0; i<11; i++) {
int id = it->getUInt(NPCDB::HelmID+i);
if (id == 0)
continue;
try {
ItemDB::Record r = itemdb.getByDisplayId(id);
} catch (ItemDB::NotFound) {
if (!items.avaiable(id+ItemDB::MaxItem)) {
int type = slots[i];
name.Printf(_T("NPC%d"), it->getUInt(NPCDB::NPCID));
ret = items.addDiscoveryDisplayId(id, name, type);
if (f.is_open() && ret != _T(""))
f << ret.mb_str() << endl;
}
}
}
}
// 4. from model dir
// 5. from blp dir
wxLogMessage(_T("Discovery done."));
if (f.is_open())
f.close();
items.cleanup(itemdisplaydb);
}

void ModelViewer::OnExport(wxCommandEvent &event)
{
// If nothing's on the canvas, stop.
if ((!canvas->model) && (!canvas->wmo))
return;

int id = event.GetId();

// Determine if this model should be in the initial pose or not.
bool init = false;
if (exportMenu->IsChecked(ID_MODELEXPORT_INIT) == true){
init = true;
}

// Set Default filename
wxString newfilename;
if (canvas->wmo) {
newfilename << wxString(canvas->wmo->name.c_str(), wxConvUTF8).AfterLast('\\').BeforeLast('.');
}else if (canvas->model) {
newfilename << wxString(canvas->model->name.c_str(), wxConvUTF8).AfterLast('\\').BeforeLast('.');
}

// Identifies the ID for this export option, and does the nessicary functions.
if (id == ID_MODELEXPORT_LWO) {
// Adds the proper extention to our default filename.
newfilename << _T(".lwo");
// For M2 Models
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Lightwave (*.lwo)|*.lwo"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

// Your M2 export function goes here.
ExportM2toLWO(canvas->root,canvas->model,dialog.GetPath().fn_str(),init);
}
// For WMO Models. This should be included, even if it isn't supported yet!
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Lightwave (*.lwo)|*.lwo"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

// Your WMO export function goes here.
ExportWMOtoLWO(canvas->wmo, dialog.GetPath().fn_str());
}
}
// That's all folks!

#ifdef _DEBUG
// Experimental new LWO Exporter!!
} else if (id == ID_MODELEXPORT_LWO2) {
newfilename << _T(".lwo");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Lightwave (*.lwo)|*.lwo"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toLWO(canvas->root, canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Lightwave (*.lwo)|*.lwo"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoLWO2(canvas->wmo, dialog.GetPath().fn_str());
}
}
#endif
} else if (id == ID_MODELEXPORT_OBJ) {
newfilename << _T(".obj");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Wavefront (*.obj)|*.obj"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toOBJ(canvas->root, canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Wavefront (*.obj)|*.obj"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoOBJ(canvas->wmo, dialog.GetPath().fn_str());
}
}
} else if (id == ID_MODELEXPORT_COLLADA) {
newfilename << _T(".dae");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Collada (*.dae)|*.dae"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toCOLLADA(canvas->root, canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Collada (*.dae)|*.dae"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoCOLLADA(canvas->wmo, dialog.GetPath().fn_str());
}
}
} else if (id == ID_MODELEXPORT_MS3D) {
newfilename << _T(".ms3d");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Milkshape 3D (*.ms3d)|*.ms3d"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toMS3D(canvas->root, canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Milkshape 3D (*.ms3d)|*.ms3d"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoMS3D(canvas->wmo, dialog.GetPath().fn_str());
}
}
} else if (id == ID_MODELEXPORT_3DS) {
newfilename << _T(".3ds");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("3D Studio Max (*.3ds)|*.3ds"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2to3DS(canvas->root, canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("3D Studio Max (*.3ds)|*.3ds"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOto3DS(canvas->wmo, dialog.GetPath().fn_str());
}
}
} else if (id == ID_MODELEXPORT_X3D) {
newfilename << _T(".x3d");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("X3D (*.x3d)|*.x3d"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toX3D(canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("X3D (*.x3d)|*.x3d"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoX3D(canvas->wmo, dialog.GetPath().fn_str());
}
}
} else if (id == ID_MODELEXPORT_XHTML) {
newfilename << _T(".xhtml");
if (canvas->model) {
wxFileDialog dialog(this, _T("Export Model..."), wxEmptyString, newfilename, _T("Embedded X3D in XHTML (*.xhtml)|*.xhtml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportM2toXHTML(canvas->model, dialog.GetPath().fn_str(), init);
}
} else if (canvas->wmo) {
wxFileDialog dialog(this, _T("Export World Model Object..."), wxEmptyString, newfilename, _T("Embedded X3D in XHTML (*.xhtml)|*.xhtml"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal()==wxID_OK) {
wxLogMessage(_T("Info: Exporting model to %s..."), wxString(dialog.GetPath().fn_str(), wxConvUTF8).c_str());

ExportWMOtoXHTML(canvas->wmo, dialog.GetPath().fn_str());
}
}
}
}



// Other things to export...
void ModelViewer::OnExportOther(wxCommandEvent &event)
{
int id = event.GetId();
if (id == ID_FILE_MODEL_INFO) {
ModelInfo();
} else if (id == ID_FILE_DISCOVERY_ITEM) {
DiscoveryItem();
fileMenu->Enable(ID_FILE_DISCOVERY_ITEM, false);
} else if (id == ID_FILE_DISCOVERY_NPC) {
DiscoveryNPC();
fileMenu->Enable(ID_FILE_DISCOVERY_NPC, false);
}
}

void ModelViewer::OnTest(wxCommandEvent &event)
{
if (!charControl->charAtt)
return;

if (arrowControl) {
arrowControl->Show(true);
} else {
arrowControl = new ArrowControl(this, wxID_ANY, wxDefaultPosition, charControl->charAtt);
/* // wxIFM stuff
arrowControlPanel = new wxIFMDefaultChildData(arrowControl, IFM_CHILD_GENERIC, wxDefaultPosition, wxSize(140, 300), true, _("Arrow Control"));
arrowControlPanel->m_orientation = IFM_ORIENTATION_FLOAT;
interfaceManager->AddChild(arrowControlPanel);
interfaceManager->Update(IFM_DEFAULT_RECT,true);

interfaceManager->ShowChild(arrowControl,true,true);
*/
// wxAUI
interfaceManager.AddPane(arrowControl, wxAuiPaneInfo().
Name(wxT("Arrows")).Caption(_("Arrows")).
FloatingSize(wxSize(150,300)).Float().Show(true)); //.FloatingPosition(GetStartPosition())
interfaceManager.Update();
}
}

void ModelViewer::UpdateControls()
{
if (!canvas || !canvas->model || !canvas->root)
return;

if (canvas->model->modelType == MT_NPC)
charControl->RefreshNPCModel();
else if (canvas->model->modelType == MT_CHAR)
charControl->RefreshModel();

modelControl->RefreshModel(canvas->root);
}

void ModelViewer::ImportArmoury(wxString strURL)
{
// Format the URL
wxString strDomain = strURL.BeforeLast(_T('/')); // "armory.worldofwarcraft.com"
strDomain = strDomain.AfterLast(_T('/'));
wxString strFile = strURL.AfterLast(_T('/')).BeforeFirst(_T('?r='));
wxString strRealm = strURL.AfterFirst(_T('?r=')).BeforeLast(_T('&n='));
wxString strChar = strURL.AfterLast(_T('&n='));

// Char Name Corrections
// Done so names like Daïmhôndrùs will get the proper page...
strChar = wxString(strChar.ToUTF8(), wxConvUTF8);

// Build Page file
// "/character-sheet.xml?r=%s&n=%s"
wxString strPage = _T('/') + strFile;
strPage.Append(_T("=")).Append(strRealm).Append(_T("=")).Append(strChar);
//http://armory.wow-europe.com/character-sheet.xml?r=Spinebreaker&n=Nostrum

wxLogMessage(_T("Attemping to access WoWArmory Page: %s"), strDomain + strPage);

// Get the page from the armoury website
wxHTTP http;

// set the headers
http.SetHeader(_T("User-Agent"), _T("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2 WoWModelViewer/0.5.08"));
http.SetHeader(_T("Accept"), _T("text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"));
http.SetHeader(_T("Accept-Language"), _T("en-us,en;q=0.5"));
http.SetHeader(_T("Accept-Charset"), _T("ISO-8859-1,utf-8;q=0.7,*;q=0.7"));

if (http.Connect(strDomain))
{
// Success
wxInputStream *stream = http.GetInputStream(strPage);
if (!stream->IsOk())
return;

// Make sure there was no error retrieving the page
if(http.GetError() == wxPROTO_NOERR) {
wxFileOutputStream output(_T("temp.xml"));
stream->Read(output);
output.Close();

wxXmlDocument xmlDoc;
if (!xmlDoc.Load(_T("temp.xml"), _T("UTF-8")))
return;

// character-model.xml?r=Realm&cn=CharacterName
// Model Details, to be decoded later

// start processing the XML file
if (xmlDoc.GetRoot()->GetName() != wxT("page"))
return;

wxXmlNode *child = xmlDoc.GetRoot()->GetChildren(); // page->tabInfo
while(child) {
if (child->GetName() == _T("characterInfo"))
break;
child = child->GetNext(); // page->characterInfo
}

if (!child)
return;

child = child->GetChildren();

while (child) {

if (child->GetName() == _T("character")) { // page->characterInfo->character

// process text enclosed by <tag1></tag1>
//wxString content = child->GetNodeContent();

// process properties of <tag1>, raceId will better?
/*
wxString race = child->GetPropVal(_T("race"), _T("Human"));
if (race == "Undead")
race = "Scourge";
else if (race == "Blood Elf")
race = "BloodElf";
else if (race == "Night Elf")
race = "NightElf";
*/
int raceId = wxAtoi(child->GetPropVal(_T("raceId"), _T("1")));
CharRacesDB::Record racer = racedb.getById(raceId);
wxString race;
if (gameVersion == 30100)
race = racer.getString(CharRacesDB::NameV310);
else
race = racer.getString(CharRacesDB::Name);
//race = race.MakeLower();
wxString gender = child->GetPropVal(_T("gender"), _T("Male"));
//gender = gender.MakeLower();

wxString strModel = _T("Character\\") + race + _T("\\") + gender + _T("\\") + race + gender + _T(".m2");

LoadModel(strModel);

if (!g_canvas->model)
return;

} else if (child->GetName() == _T("characterTab")) { // page->characterInfo->characterTab
child = child->GetChildren();

} else if (child->GetName() == _T("items")) { // page->characterInfo->characterTab->items

wxXmlNode *itemNode = child->GetChildren();
while (itemNode) { // // page->characterInfo->characterTab->items->item
if (itemNode->GetName() == _T("item")) {
wxString id = itemNode->GetPropVal(_T("id"), _T("0"));
wxString slot = itemNode->GetPropVal(_T("slot"), _T("0"));

// Item ID
long itemID;
id.ToLong(&itemID);

// Equipment Slot
long slotID;
slot.ToLong(&slotID);

// Manual correction for slot ID values
if (slotID == 4) // Chest
slotID = CS_CHEST;
else if (slotID == 5) // Waist
slotID = CS_BELT;
else if (slotID == 7) // Feet
slotID = CS_BOOTS;
else if (slotID == 14) // Back
slotID = CS_CAPE;
else if (slotID == 15) // Right Hand
slotID = CS_HAND_RIGHT;
else if (slotID == 16) // Left Hand
slotID = CS_HAND_LEFT;

g_charControl->cd.equipment[slotID] = itemID;
}

itemNode = itemNode->GetNext();
}

// Update the model
g_charControl->RefreshModel();
g_charControl->RefreshEquipment();
break;
}

child = child->GetNext();
}

//wxRemoveFile(_T("temp.xml"));
}
delete stream;
}
}

// --

Change log

r154 by sephiroth3d on May 10, 2010   Diff
-WMV will now produce an error message if
it can't find the World of Warcraft
directory.
-WMV now wants you to specify the WoW
directory, not the WoW/Data directory.
-In Windows, WMV will now prompt for the
user to select their WoW directory if it
can't find the registry info.
Go to: 
Project members, sign in to write a code review

Older revisions

r149 by chuanhsing on May 10, 2010   Diff
- Expanded Cataclysm support.
r145 by chuanhsing on May 9, 2010   Diff
- Expanded Cataclysm support.
r144 by chuanhsing on May 9, 2010   Diff
- Expanded Cataclysm support.
All revisions of this file

File info

Size: 115093 bytes, 3227 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting