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
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
|
/**
* @file llfloatermodelpreview.cpp
* @brief LLFloaterModelPreview class implementation
*
* $LicenseInfo:firstyear=2004&license=viewergpl$
*
* Copyright (c) 2004-2007, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlife.com/developers/opensource/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlife.com/developers/opensource/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "dae.h"
//#include "dom.h"
#include "dom/domAsset.h"
#include "dom/domBind_material.h"
#include "dom/domCOLLADA.h"
#include "dom/domConstants.h"
#include "dom/domController.h"
#include "dom/domEffect.h"
#include "dom/domGeometry.h"
#include "dom/domInstance_geometry.h"
#include "dom/domInstance_material.h"
#include "dom/domInstance_node.h"
#include "dom/domInstance_effect.h"
#include "dom/domMaterial.h"
#include "dom/domMatrix.h"
#include "dom/domNode.h"
#include "dom/domProfile_COMMON.h"
#include "dom/domRotate.h"
#include "dom/domScale.h"
#include "dom/domTranslate.h"
#include "dom/domVisual_scene.h"
#include "llfloatermodelpreview.h"
#include "llfilepicker.h"
#include "llimagebmp.h"
#include "llimagetga.h"
#include "llimagejpeg.h"
#include "llimagepng.h"
#include "llagent.h"
#include "llbutton.h"
#include "llcombobox.h"
#include "lldatapacker.h"
#include "lldrawable.h"
#include "lldrawpoolavatar.h"
#include "llrender.h"
#include "llface.h"
#include "lleconomy.h"
#include "llfocusmgr.h"
#include "llfloaterperms.h"
#include "llmatrix4a.h"
#include "llmeshrepository.h"
#include "llsdutil_math.h"
#include "lltextbox.h"
#include "lltoolmgr.h"
#include "llui.h"
#include "llvector4a.h"
#include "llviewercamera.h"
#include "llviewerwindow.h"
#include "llvoavatar.h"
#include "llvoavatarself.h"
#include "pipeline.h"
#include "lluictrlfactory.h"
#include "llviewermenufile.h"
#include "llviewerregion.h"
#include "llstring.h"
#include "llbutton.h"
#include "llcheckboxctrl.h"
#include "llsliderctrl.h"
#include "llspinctrl.h"
#include "llvfile.h"
#include "llvfs.h"
#include "glod/glod.h"
#if LL_MESH_ENABLED
//static
S32 LLFloaterModelPreview::sUploadAmount = 10;
LLFloaterModelPreview* LLFloaterModelPreview::sInstance = NULL;
const S32 PREVIEW_BORDER_WIDTH = 2;
const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
const S32 PREF_BUTTON_HEIGHT = 16 + 7 + 16;
const S32 PREVIEW_TEXTURE_HEIGHT = 300;
void drawBoxOutline(const LLVector3& pos, const LLVector3& size);
std::string limit_name[] =
{
"lowest limit",
"low limit",
"medium limit",
"high limit",
"physics limit",
"I went off the end of the limit_name array. Me so smart."
};
std::string info_name[] =
{
"lowest info",
"low info",
"medium info",
"high info",
"physics info",
"I went off the end of the info_name array. Me so smart."
};
bool validate_face(const LLVolumeFace& face)
{
for (U32 i = 0; i < face.mNumIndices; ++i)
{
if (face.mIndices[i] >= face.mNumVertices)
{
llwarns << "Face has invalid index." << llendl;
return false;
}
}
return true;
}
bool validate_model(const LLModel* mdl)
{
if (mdl->getNumVolumeFaces() == 0)
{
llwarns << "Model has no faces!" << llendl;
return false;
}
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
if (mdl->getVolumeFace(i).mNumVertices == 0)
{
llwarns << "Face has no vertices." << llendl;
return false;
}
if (mdl->getVolumeFace(i).mNumIndices == 0)
{
llwarns << "Face has no indices." << llendl;
return false;
}
if (!validate_face(mdl->getVolumeFace(i)))
{
return false;
}
}
return true;
}
BOOL stop_gloderror()
{
GLuint error = glodGetError();
if (error != GLOD_NO_ERROR)
{
llwarns << "GLOD error detected, cannot generate LOD: " << std::hex << error << llendl;
return TRUE;
}
return FALSE;
}
LLPhysicsDecompFloater::LLPhysicsDecompFloater(LLSD& key)
: LLFloater(key)
{
}
LLPhysicsDecompFloater::~LLPhysicsDecompFloater()
{
if (LLFloaterModelPreview::sInstance && LLFloaterModelPreview::sInstance->mDecompFloater)
{
LLFloaterModelPreview::sInstance->mDecompFloater = NULL;
}
}
class LLMeshFilePicker : public LLFilePickerThread
{
public:
LLFloaterModelPreview* mFMP;
S32 mLOD;
LLMeshFilePicker(LLFloaterModelPreview* fmp, S32 lod)
: LLFilePickerThread(LLFilePicker::FFLOAD_COLLADA)
{
mFMP = fmp;
mLOD = lod;
}
virtual void notify(const std::string& filename)
{
mFMP->mModelPreview->loadModel(mFile, mLOD);
}
};
//-----------------------------------------------------------------------------
// LLFloaterModelPreview()
//-----------------------------------------------------------------------------
LLFloaterModelPreview::LLFloaterModelPreview(const LLSD& key) :
LLFloater(key)
{
sInstance = this;
mLastMouseX = 0;
mLastMouseY = 0;
mGLName = 0;
mLoading = FALSE;
mDecompFloater = NULL;
}
//-----------------------------------------------------------------------------
// postBuild()
//-----------------------------------------------------------------------------
BOOL LLFloaterModelPreview::postBuild()
{
if (!LLFloater::postBuild())
{
return FALSE;
}
childSetCommitCallback("high detail combo", onHighLODCommit, this);
childSetCommitCallback("medium detail combo", onMediumLODCommit, this);
childSetCommitCallback("low detail combo", onLowLODCommit, this);
childSetCommitCallback("lowest detail combo", onLowestLODCommit, this);
childSetCommitCallback("physics detail combo", onPhysicsLODCommit, this);
childSetCommitCallback("high limit", onHighLimitCommit, this);
childSetCommitCallback("medium limit", onMediumLimitCommit, this);
childSetCommitCallback("low limit", onLowLimitCommit, this);
childSetCommitCallback("lowest limit", onLowestLimitCommit, this);
childSetCommitCallback("physics limit", onPhysicsLimitCommit, this);
childSetCommitCallback("smooth normals", onSmoothNormalsCommit, this);
childSetCommitCallback("show edges", onShowEdgesCommit, this);
childSetCommitCallback("auto fill", onAutoFillCommit, this);
childSetCommitCallback("explode", onExplodeCommit, this);
childSetTextArg("status", "[STATUS]", getString("status_idle"));
for (S32 lod = 0; lod < LLModel::NUM_LODS; ++lod)
{
if (lod == LLModel::LOD_PHYSICS)
{
childSetTextArg(info_name[lod], "[HULLS]", std::string("0"));
childSetTextArg(info_name[lod], "[POINTS]", std::string("0"));
}
else
{
childSetTextArg(info_name[lod], "[TRIANGLES]", std::string("0"));
childSetTextArg(info_name[lod], "[VERTICES]", std::string("0"));
childSetTextArg(info_name[lod], "[SUBMESHES]", std::string("0"));
std::string msg = getString("required");
childSetTextArg(info_name[lod], "[MESSAGE]", msg);
}
childSetVisible(limit_name[lod], FALSE);
}
//childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",sUploadAmount));
childSetAction("ok_btn", onUpload, this);
childSetAction("consolidate", onConsolidate, this);
childSetAction("scrub materials", onScrubMaterials, this);
childSetAction("decompose_btn", onDecompose, this);
childSetCommitCallback("preview_lod_combo", onPreviewLODCommit, this);
const U32 width = 512;
const U32 height = 512;
mPreviewRect.set(getRect().getWidth()-PREVIEW_HPAD-width,
PREVIEW_HPAD+height,
getRect().getWidth()-PREVIEW_HPAD,
PREVIEW_HPAD);
mModelPreview = new LLModelPreview(512, 512, this);
mModelPreview->setPreviewTarget(16.f);
return TRUE;
}
//-----------------------------------------------------------------------------
// LLFloaterModelPreview()
//-----------------------------------------------------------------------------
LLFloaterModelPreview::~LLFloaterModelPreview()
{
sInstance = NULL;
delete mModelPreview;
if (mGLName)
{
LLImageGL::deleteTextures(1, &mGLName );
}
if (mDecompFloater)
{
mDecompFloater->closeFloater();
mDecompFloater = NULL;
}
}
void LLFloaterModelPreview::loadModel(S32 lod)
{
mLoading = TRUE;
(new LLMeshFilePicker(this, lod))->getFile();
}
void LLFloaterModelPreview::setLODMode(S32 lod, S32 mode)
{
if (mode == 0)
{
loadModel(lod);
}
else if (mode != mModelPreview->mLODMode[lod])
{
mModelPreview->mLODMode[lod] = mode;
mModelPreview->genLODs(lod);
}
mModelPreview->setPreviewLOD(lod);
LLSpinCtrl* lim = getChild<LLSpinCtrl>(limit_name[lod], TRUE);
if (mode == 1) //triangle count
{
U32 tri_count = 0;
for (LLModelLoader::model_list::iterator iter = mModelPreview->mBaseModel.begin();
iter != mModelPreview->mBaseModel.end(); ++iter)
{
tri_count += (*iter)->getNumTriangles();
}
lim->setMaxValue(tri_count);
lim->setVisible(TRUE);
}
else
{
lim->setVisible(FALSE);
}
}
void LLFloaterModelPreview::setLimit(S32 lod, S32 limit)
{
if (limit != mModelPreview->mLimit[lod])
{
mModelPreview->mLimit[lod] = limit;
mModelPreview->genLODs(lod);
mModelPreview->setPreviewLOD(lod);
}
}
void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
if (!fp->mModelPreview)
{
return;
}
S32 which_mode = 0;
LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface("preview_lod_combo");
if (iface)
{
which_mode = iface->getFirstSelectedIndex();
}
fp->mModelPreview->setPreviewLOD(which_mode);
}
//static
void LLFloaterModelPreview::setLODMode(S32 lod, void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
if (!fp->mModelPreview)
{
return;
}
S32 which_mode = 0;
std::string combo_name[] =
{
"lowest detail combo",
"low detail combo",
"medium detail combo",
"high detail combo",
"physics detail combo",
"I went off the end of the combo_name array. Me so smart."
};
LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface(combo_name[lod]);
if (iface)
{
which_mode = iface->getFirstSelectedIndex();
}
fp->setLODMode(lod, which_mode);
}
//static
void LLFloaterModelPreview::onHighLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLODMode(3, userdata);
}
//static
void LLFloaterModelPreview::onMediumLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLODMode(2, userdata);
}
//static
void LLFloaterModelPreview::onLowLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLODMode(1, userdata);
}
//static
void LLFloaterModelPreview::onLowestLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLODMode(0, userdata);
}
//static
void LLFloaterModelPreview::onPhysicsLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLODMode(4, userdata);
}
//static
void LLFloaterModelPreview::setLimit(S32 lod, void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
if (!fp->mModelPreview)
{
return;
}
S32 limit = fp->childGetValue(limit_name[lod]).asInteger();
fp->setLimit(lod, limit);
}
//static
void LLFloaterModelPreview::onHighLimitCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLimit(3, userdata);
}
//static
void LLFloaterModelPreview::onMediumLimitCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLimit(2, userdata);
}
//static
void LLFloaterModelPreview::onLowLimitCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLimit(1, userdata);
}
//static
void LLFloaterModelPreview::onLowestLimitCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLimit(0, userdata);
}
//static
void LLFloaterModelPreview::onPhysicsLimitCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview::setLimit(4, userdata);
}
//static
void LLFloaterModelPreview::onSmoothNormalsCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
fp->mModelPreview->smoothNormals();
}
//static
void LLFloaterModelPreview::onShowEdgesCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
fp->mModelPreview->refresh();
}
//static
void LLFloaterModelPreview::onExplodeCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
fp->mModelPreview->refresh();
}
//static
void LLFloaterModelPreview::onAutoFillCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
fp->mModelPreview->genLODs();
}
//-----------------------------------------------------------------------------
// draw()
//-----------------------------------------------------------------------------
void LLFloaterModelPreview::draw()
{
LLFloater::draw();
LLRect r = getRect();
mModelPreview->update();
if (!mLoading)
{
childSetTextArg("status", "[STATUS]", getString("status_idle"));
}
childSetTextArg("description_label", "[PRIM_COST]", llformat("%d", mModelPreview->mResourceCost));
childSetTextArg("description_label", "[TEXTURES]", llformat("%d", mModelPreview->mTextureSet.size()));
if (mDecompFloater)
{
mDecompFloater->childSetText("status", gMeshRepo.mDecompThread->mStatus);
}
U32 resource_cost = mModelPreview->mResourceCost*10;
if (childGetValue("upload_textures").asBoolean())
{
resource_cost += mModelPreview->mTextureSet.size()*10;
}
childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d", resource_cost));
if (mModelPreview)
{
gGL.color3f(1.f, 1.f, 1.f);
gGL.getTexUnit(0)->bind(mModelPreview);
gGL.begin( LLRender::QUADS );
{
gGL.texCoord2f(0.f, 1.f);
gGL.vertex2i(mPreviewRect.mLeft, mPreviewRect.mTop);
gGL.texCoord2f(0.f, 0.f);
gGL.vertex2i(mPreviewRect.mLeft, mPreviewRect.mBottom);
gGL.texCoord2f(1.f, 0.f);
gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mBottom);
gGL.texCoord2f(1.f, 1.f);
gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mTop);
}
gGL.end();
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
}
}
//-----------------------------------------------------------------------------
// handleMouseDown()
//-----------------------------------------------------------------------------
BOOL LLFloaterModelPreview::handleMouseDown(S32 x, S32 y, MASK mask)
{
if (mPreviewRect.pointInRect(x, y))
{
bringToFront( x, y );
gFocusMgr.setMouseCapture(this);
gViewerWindow->hideCursor();
mLastMouseX = x;
mLastMouseY = y;
return TRUE;
}
return LLFloater::handleMouseDown(x, y, mask);
}
//-----------------------------------------------------------------------------
// handleMouseUp()
//-----------------------------------------------------------------------------
BOOL LLFloaterModelPreview::handleMouseUp(S32 x, S32 y, MASK mask)
{
gFocusMgr.setMouseCapture(FALSE);
gViewerWindow->showCursor();
return LLFloater::handleMouseUp(x, y, mask);
}
//-----------------------------------------------------------------------------
// handleHover()
//-----------------------------------------------------------------------------
BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask)
{
MASK local_mask = mask & ~MASK_ALT;
if (mModelPreview && hasMouseCapture())
{
if (local_mask == MASK_PAN)
{
// pan here
mModelPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
}
else if (local_mask == MASK_ORBIT)
{
F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
mModelPreview->rotate(yaw_radians, pitch_radians);
}
else
{
F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
mModelPreview->rotate(yaw_radians, 0.f);
mModelPreview->zoom(zoom_amt);
}
mModelPreview->refresh();
LLUI::setMousePositionLocal(this, mLastMouseX, mLastMouseY);
}
if (!mPreviewRect.pointInRect(x, y) || !mModelPreview)
{
return LLFloater::handleHover(x, y, mask);
}
else if (local_mask == MASK_ORBIT)
{
gViewerWindow->setCursor(UI_CURSOR_TOOLCAMERA);
}
else if (local_mask == MASK_PAN)
{
gViewerWindow->setCursor(UI_CURSOR_TOOLPAN);
}
else
{
gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
}
return TRUE;
}
//-----------------------------------------------------------------------------
// handleScrollWheel()
//-----------------------------------------------------------------------------
BOOL LLFloaterModelPreview::handleScrollWheel(S32 x, S32 y, S32 clicks)
{
if (mPreviewRect.pointInRect(x, y) && mModelPreview)
{
mModelPreview->zoom((F32)clicks * -0.2f);
mModelPreview->refresh();
}
return TRUE;
}
//static
void LLFloaterModelPreview::onPhysicsParamCommit(LLUICtrl* ctrl, void* data)
{
LLCDParam* param = (LLCDParam*) data;
LLCDResult ret = LLCD_OK;
if (LLConvexDecomposition::getInstance() == NULL)
{
llinfos << "convex decomposition tool is a stub on this platform. cannot get decomp." << llendl;
return;
}
if (param->mType == LLCDParam::LLCD_FLOAT)
{
ret = LLConvexDecomposition::getInstance()->setParam(param->mName, (F32) ctrl->getValue().asReal());
}
else if (param->mType == LLCDParam::LLCD_INTEGER ||
param->mType == LLCDParam::LLCD_ENUM)
{
ret = LLConvexDecomposition::getInstance()->setParam(param->mName, ctrl->getValue().asInteger());
}
else if (param->mType == LLCDParam::LLCD_BOOLEAN)
{
ret = LLConvexDecomposition::getInstance()->setParam(param->mName, ctrl->getValue().asBoolean());
}
if (ret)
{
llerrs << "WTF?" << llendl;
}
}
//static
void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data)
{
LLCDStageData* stage = (LLCDStageData*) data;
LLModel* mdl = NULL;
if (sInstance)
{
if (sInstance->mModelPreview)
{
if (sInstance->mDecompFloater)
{
S32 idx = sInstance->mDecompFloater->childGetValue("model").asInteger();
if (idx >= 0 && idx < sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS].size())
{
mdl = sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS][idx];
}
}
}
}
if (mdl)
{
gMeshRepo.mDecompThread->execute(stage->mName, mdl);
}
}
//static
void LLFloaterModelPreview::onPhysicsStageCancel(LLUICtrl* ctrl, void*data)
{
gMeshRepo.mDecompThread->cancel();
}
void LLFloaterModelPreview::showDecompFloater()
{
if (!mDecompFloater)
{
LLSD key;
mDecompFloater = new LLPhysicsDecompFloater(key);
S32 left = 20;
S32 right = 270;
S32 cur_y = 30;
{
//add status text
LLTextBox::Params p;
p.name("status");
p.rect(LLRect(left, cur_y, right-80, cur_y-20));
mDecompFloater->addChild(LLUICtrlFactory::create<LLTextBox>(p));
}
{ //add cancel button
LLButton::Params p;
p.name("Cancel");
p.label("Cancel");
p.rect(LLRect(right-80, cur_y, right, cur_y-20));
LLButton* button = LLUICtrlFactory::create<LLButton>(p);
button->setCommitCallback(onPhysicsStageCancel, NULL);
mDecompFloater->addChild(button);
}
cur_y += 30;
const LLCDStageData* stage;
S32 stage_count = 0;
if (LLConvexDecomposition::getInstance() != NULL)
{
stage_count = LLConvexDecomposition::getInstance()->getStages(&stage);
}
const LLCDParam* param;
S32 param_count = 0;
if (LLConvexDecomposition::getInstance() != NULL)
{
param_count = LLConvexDecomposition::getInstance()->getParameters(¶m);
}
for (S32 j = stage_count-1; j >= 0; --j)
{
LLButton::Params p;
p.name(stage[j].mName);
p.label(stage[j].mName);
p.rect(LLRect(left, cur_y, right, cur_y-20));
LLButton* button = LLUICtrlFactory::create<LLButton>(p);
button->setCommitCallback(onPhysicsStageExecute, (void*) &stage[j]);
mDecompFloater->addChild(button);
gMeshRepo.mDecompThread->mStageID[stage[j].mName] = j;
cur_y += 30;
// protected against stub by stage_count being 0 for stub above
LLConvexDecomposition::getInstance()->registerCallback(j, LLPhysicsDecomp::llcdCallback);
for (S32 i = 0; i < param_count; ++i)
{
if (param[i].mStage != j)
{
continue;
}
if (param[i].mType == LLCDParam::LLCD_FLOAT)
{
LLSliderCtrl::Params p;
p.name(param[i].mName);
p.label(param[i].mName);
p.rect(LLRect(left, cur_y, right, cur_y-20));
p.min_value(param[i].mDetails.mRange.mLow.mFloat);
p.max_value(param[i].mDetails.mRange.mHigh.mFloat);
p.increment(param[i].mDetails.mRange.mDelta.mFloat);
p.decimal_digits(3);
p.initial_value(param[i].mDefault.mFloat);
LLSliderCtrl* slider = LLUICtrlFactory::create<LLSliderCtrl>(p);
slider->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]);
mDecompFloater->addChild(slider);
cur_y += 30;
}
else if (param[i].mType == LLCDParam::LLCD_INTEGER)
{
LLSliderCtrl::Params p;
p.name(param[i].mName);
p.label(param[i].mName);
p.rect(LLRect(left, cur_y, right, cur_y-20));
p.min_value(param[i].mDetails.mRange.mLow.mIntOrEnumValue);
p.max_value(param[i].mDetails.mRange.mHigh.mIntOrEnumValue);
p.increment(param[i].mDetails.mRange.mDelta.mIntOrEnumValue);
p.initial_value(param[i].mDefault.mIntOrEnumValue);
LLSliderCtrl* slider = LLUICtrlFactory::create<LLSliderCtrl>(p);
slider->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]);
mDecompFloater->addChild(slider);
cur_y += 30;
}
else if (param[i].mType == LLCDParam::LLCD_BOOLEAN)
{
LLCheckBoxCtrl::Params p;
p.rect(LLRect(left, cur_y, right, cur_y-20));
p.name(param[i].mName);
p.label(param[i].mName);
p.initial_value(param[i].mDefault.mBool);
LLCheckBoxCtrl* check_box = LLUICtrlFactory::create<LLCheckBoxCtrl>(p);
check_box->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]);
mDecompFloater->addChild(check_box);
cur_y += 30;
}
else if (param[i].mType == LLCDParam::LLCD_ENUM)
{
LLComboBox::Params p;
p.rect(LLRect(left, cur_y, right/3, cur_y-20));
p.name(param[i].mName);
p.label(param[i].mName);
LLComboBox* combo_box = LLUICtrlFactory::create<LLComboBox>(p);
for (S32 k = 0; k < param[i].mDetails.mEnumValues.mNumEnums; ++k)
{
combo_box->add(param[i].mDetails.mEnumValues.mEnumsArray[k].mName,
LLSD::Integer(param[i].mDetails.mEnumValues.mEnumsArray[k].mValue));
}
combo_box->setValue(param[i].mDefault.mIntOrEnumValue);
combo_box->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]);
mDecompFloater->addChild(combo_box);
cur_y += 30;
}
}
}
//mesh render checkbox
{
LLCheckBoxCtrl::Params p;
p.label("Mesh: ");
p.name("render_mesh");
p.rect(LLRect(left, cur_y, right/4, cur_y-20));
LLCheckBoxCtrl* check = LLUICtrlFactory::create<LLCheckBoxCtrl>(p);
check->setValue(true);
mDecompFloater->addChild(check);
}
//hull render checkbox
{
LLCheckBoxCtrl::Params p;
p.label("Hull: ");
p.name("render_hull");
p.rect(LLRect(right/4, cur_y, right/2, cur_y-20));
LLCheckBoxCtrl* check = LLUICtrlFactory::create<LLCheckBoxCtrl>(p);
check->setValue(true);
mDecompFloater->addChild(check);
}
{ //submesh combo box label
LLTextBox::Params p;
p.label("Model");
p.name("model label");
p.rect(LLRect(right/3, cur_y, right/2, cur_y-20));
LLTextBox* text_box = LLUICtrlFactory::create<LLTextBox>(p);
text_box->setValue("Model");
mDecompFloater->addChild(text_box);
}
{
//add submesh combo box
LLComboBox::Params p;
p.rect(LLRect(right/2, cur_y, right, cur_y-20));
p.name("model");
LLComboBox* combo_box = LLUICtrlFactory::create<LLComboBox>(p);
for (S32 i = 0; i < mModelPreview->mBaseModel.size(); ++i)
{
LLModel* mdl = mModelPreview->mBaseModel[i];
combo_box->add(mdl->mLabel, i);
}
combo_box->setValue(0);
mDecompFloater->addChild(combo_box);
cur_y += 30;
}
mDecompFloater->childSetCommitCallback("model", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance);
mDecompFloater->childSetCommitCallback("render_mesh", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance);
mDecompFloater->childSetCommitCallback("render_hull", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance);
mDecompFloater->setRect(LLRect(10, cur_y+20, right+20, 10));
}
mDecompFloater->openFloater();
}
//-----------------------------------------------------------------------------
// onMouseCaptureLost()
//-----------------------------------------------------------------------------
// static
void LLFloaterModelPreview::onMouseCaptureLostModelPreview(LLMouseHandler* handler)
{
gViewerWindow->showCursor();
}
//-----------------------------------------------------------------------------
// LLModelLoader
//-----------------------------------------------------------------------------
LLModelLoader::LLModelLoader(std::string filename, S32 lod, LLModelPreview* preview)
: LLThread("Model Loader"), mFilename(filename), mLod(lod), mPreview(preview), mState(STARTING), mFirstTransform(TRUE)
{
mJointMap["mPelvis"] = "mPelvis";
mJointMap["mTorso"] = "mTorso";
mJointMap["mChest"] = "mChest";
mJointMap["mNeck"] = "mNeck";
mJointMap["mHead"] = "mHead";
mJointMap["mSkull"] = "mSkull";
mJointMap["mEyeRight"] = "mEyeRight";
mJointMap["mEyeLeft"] = "mEyeLeft";
mJointMap["mCollarLeft"] = "mCollarLeft";
mJointMap["mShoulderLeft"] = "mShoulderLeft";
mJointMap["mElbowLeft"] = "mElbowLeft";
mJointMap["mWristLeft"] = "mWristLeft";
mJointMap["mCollarRight"] = "mCollarRight";
mJointMap["mShoulderRight"] = "mShoulderRight";
mJointMap["mElbowRight"] = "mElbowRight";
mJointMap["mWristRight"] = "mWristRight";
mJointMap["mHipRight"] = "mHipRight";
mJointMap["mKneeRight"] = "mKneeRight";
mJointMap["mAnkleRight"] = "mAnkleRight";
mJointMap["mFootRight"] = "mFootRight";
mJointMap["mToeRight"] = "mToeRight";
mJointMap["mHipLeft"] = "mHipLeft";
mJointMap["mKneeLeft"] = "mKneeLeft";
mJointMap["mAnkleLeft"] = "mAnkleLeft";
mJointMap["mFootLeft"] = "mFootLeft";
mJointMap["mToeLeft"] = "mToeLeft";
mJointMap["avatar_mPelvis"] = "mPelvis";
mJointMap["avatar_mTorso"] = "mTorso";
mJointMap["avatar_mChest"] = "mChest";
mJointMap["avatar_mNeck"] = "mNeck";
mJointMap["avatar_mHead"] = "mHead";
mJointMap["avatar_mSkull"] = "mSkull";
mJointMap["avatar_mEyeRight"] = "mEyeRight";
mJointMap["avatar_mEyeLeft"] = "mEyeLeft";
mJointMap["avatar_mCollarLeft"] = "mCollarLeft";
mJointMap["avatar_mShoulderLeft"] = "mShoulderLeft";
mJointMap["avatar_mElbowLeft"] = "mElbowLeft";
mJointMap["avatar_mWristLeft"] = "mWristLeft";
mJointMap["avatar_mCollarRight"] = "mCollarRight";
mJointMap["avatar_mShoulderRight"] = "mShoulderRight";
mJointMap["avatar_mElbowRight"] = "mElbowRight";
mJointMap["avatar_mWristRight"] = "mWristRight";
mJointMap["avatar_mHipRight"] = "mHipRight";
mJointMap["avatar_mKneeRight"] = "mKneeRight";
mJointMap["avatar_mAnkleRight"] = "mAnkleRight";
mJointMap["avatar_mFootRight"] = "mFootRight";
mJointMap["avatar_mToeRight"] = "mToeRight";
mJointMap["avatar_mHipLeft"] = "mHipLeft";
mJointMap["avatar_mKneeLeft"] = "mKneeLeft";
mJointMap["avatar_mAnkleLeft"] = "mAnkleLeft";
mJointMap["avatar_mFootLeft"] = "mFootLeft";
mJointMap["avatar_mToeLeft"] = "mToeLeft";
mJointMap["hip"] = "mPelvis";
mJointMap["abdomen"] = "mTorso";
mJointMap["chest"] = "mChest";
mJointMap["neck"] = "mNeck";
mJointMap["head"] = "mHead";
mJointMap["figureHair"] = "mSkull";
mJointMap["lCollar"] = "mCollarLeft";
mJointMap["lShldr"] = "mShoulderLeft";
mJointMap["lForeArm"] = "mElbowLeft";
mJointMap["lHand"] = "mWristLeft";
mJointMap["rCollar"] = "mCollarRight";
mJointMap["rShldr"] = "mShoulderRight";
mJointMap["rForeArm"] = "mElbowRight";
mJointMap["rHand"] = "mWristRight";
mJointMap["rThigh"] = "mHipRight";
mJointMap["rShin"] = "mKneeRight";
mJointMap["rFoot"] = "mFootRight";
mJointMap["lThigh"] = "mHipLeft";
mJointMap["lShin"] = "mKneeLeft";
mJointMap["lFoot"] = "mFootLeft";
}
void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4a& max, BOOL& first_transform)
{
LLVector4a box[] =
{
LLVector4a(-1, 1,-1),
LLVector4a(-1, 1, 1),
LLVector4a(-1,-1,-1),
LLVector4a(-1,-1, 1),
LLVector4a( 1, 1,-1),
LLVector4a( 1, 1, 1),
LLVector4a( 1,-1,-1),
LLVector4a( 1,-1, 1),
};
for (S32 j = 0; j < model->getNumVolumeFaces(); ++j)
{
const LLVolumeFace& face = model->getVolumeFace(j);
LLVector4a center;
center.setAdd(face.mExtents[0], face.mExtents[1]);
center.mul(0.5f);
LLVector4a size;
size.setSub(face.mExtents[1],face.mExtents[0]);
size.mul(0.5f);
for (U32 i = 0; i < 8; i++)
{
LLVector4a t;
t.setMul(size, box[i]);
t.add(center);
LLVector4a v;
mat.affineTransform(t, v);
if (first_transform)
{
first_transform = FALSE;
min = max = v;
}
else
{
update_min_max(min, max, v);
}
}
}
}
void stretch_extents(LLModel* model, LLMatrix4& mat, LLVector3& min, LLVector3& max, BOOL& first_transform)
{
LLVector4a mina, maxa;
LLMatrix4a mata;
mata.loadu(mat);
mina.load3(min.mV);
maxa.load3(max.mV);
stretch_extents(model, mata, mina, maxa, first_transform);
min.set(mina.getF32ptr());
max.set(maxa.getF32ptr());
}
void LLModelLoader::run()
{
DAE dae;
domCOLLADA* dom = dae.open(mFilename);
if (dom)
{
daeDatabase* db = dae.getDatabase();
daeInt count = db->getElementCount(NULL, COLLADA_TYPE_MESH);
daeDocument* doc = dae.getDoc(mFilename);
if (!doc)
{
llwarns << "can't find internal doc" << llendl;
return;
}
daeElement* root = doc->getDomRoot();
if (!root)
{
llwarns << "document has no root" << llendl;
return;
}
//get unit scale
mTransform.setIdentity();
domAsset::domUnit* unit = daeSafeCast<domAsset::domUnit>(root->getDescendant(daeElement::matchType(domAsset::domUnit::ID())));
if (unit)
{
F32 meter = unit->getMeter();
mTransform.mMatrix[0][0] = meter;
mTransform.mMatrix[1][1] = meter;
mTransform.mMatrix[2][2] = meter;
}
//get up axis rotation
LLMatrix4 rotation;
domUpAxisType up = UPAXISTYPE_Y_UP; // default is Y_UP
domAsset::domUp_axis* up_axis =
daeSafeCast<domAsset::domUp_axis>(root->getDescendant(daeElement::matchType(domAsset::domUp_axis::ID())));
if (up_axis)
{
up = up_axis->getValue();
}
if (up == UPAXISTYPE_X_UP)
{
rotation.initRotation(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
}
else if (up == UPAXISTYPE_Y_UP)
{
rotation.initRotation(90.0f * DEG_TO_RAD, 0.0f, 0.0f);
}
rotation *= mTransform;
mTransform = rotation;
for (daeInt idx = 0; idx < count; ++idx)
{ //build map of domEntities to LLModel
domMesh* mesh = NULL;
db->getElement((daeElement**) &mesh, idx, NULL, COLLADA_TYPE_MESH);
if (mesh)
{
LLPointer<LLModel> model = LLModel::loadModelFromDomMesh(mesh);
if (model.notNull() && validate_model(model))
{
mModelList.push_back(model);
mModel[mesh] = model;
}
}
}
count = db->getElementCount(NULL, COLLADA_TYPE_SKIN);
for (daeInt idx = 0; idx < count; ++idx)
{ //add skinned meshes as instances
domSkin* skin = NULL;
db->getElement((daeElement**) &skin, idx, NULL, COLLADA_TYPE_SKIN);
if (skin)
{
domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement());
if (geom)
{
domMesh* mesh = geom->getMesh();
if (mesh)
{
LLModel* model = mModel[mesh];
if (model)
{
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
model->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
LLMatrix4 normalized_transformation;
normalized_transformation.setTranslation(mesh_translation_vector);
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= normalized_transformation;
normalized_transformation = mesh_scale;
glh::matrix4f inv_mat((F32*) normalized_transformation.mMatrix);
inv_mat = inv_mat.inverse();
LLMatrix4 inverse_normalized_transformation(inv_mat.m);
domSkin::domBind_shape_matrix* bind_mat = skin->getBind_shape_matrix();
if (bind_mat)
{ //get bind shape matrix
domFloat4x4& dom_value = bind_mat->getValue();
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
model->mBindShapeMatrix.mMatrix[i][j] = dom_value[i + j*4];
}
}
LLMatrix4 trans = normalized_transformation;
trans *= model->mBindShapeMatrix;
model->mBindShapeMatrix = trans;
}
/*{
LLMatrix4 rotation;
if (up == UPAXISTYPE_X_UP)
{
rotation.initRotation(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
}
else if (up == UPAXISTYPE_Z_UP)
{
rotation.initRotation(90.0f * DEG_TO_RAD, 90.0f * DEG_TO_RAD, 0.0f);
}
rotation *= model->mBindShapeMatrix;
model->mBindShapeMatrix = rotation;
}*/
domSkin::domJoints* joints = skin->getJoints();
domInputLocal_Array& joint_input = joints->getInput_array();
for (size_t i = 0; i < joint_input.getCount(); ++i)
{
domInputLocal* input = joint_input.get(i);
xsNMTOKEN semantic = input->getSemantic();
if (strcmp(semantic, COMMON_PROFILE_INPUT_JOINT) == 0)
{ //found joint source, fill model->mJointMap and model->mJointList
daeElement* elem = input->getSource().getElement();
domSource* source = daeSafeCast<domSource>(elem);
if (source)
{
domName_array* names_source = source->getName_array();
if (names_source)
{
domListOfNames &names = names_source->getValue();
for (size_t j = 0; j < names.getCount(); ++j)
{
std::string name(names.get(j));
if (mJointMap.find(name) != mJointMap.end())
{
name = mJointMap[name];
}
model->mJointList.push_back(name);
model->mJointMap[name] = j;
}
}
else
{
domIDREF_array* names_source = source->getIDREF_array();
if (names_source)
{
xsIDREFS& names = names_source->getValue();
for (size_t j = 0; j < names.getCount(); ++j)
{
std::string name(names.get(j).getID());
if (mJointMap.find(name) != mJointMap.end())
{
name = mJointMap[name];
}
model->mJointList.push_back(name);
model->mJointMap[name] = j;
}
}
}
}
}
else if (strcmp(semantic, COMMON_PROFILE_INPUT_INV_BIND_MATRIX) == 0)
{ //found inv_bind_matrix array, fill model->mInvBindMatrix
domSource* source = daeSafeCast<domSource>(input->getSource().getElement());
if (source)
{
domFloat_array* t = source->getFloat_array();
if (t)
{
domListOfFloats& transform = t->getValue();
S32 count = transform.getCount()/16;
for (S32 k = 0; k < count; ++k)
{
LLMatrix4 mat;
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
mat.mMatrix[i][j] = transform[k*16 + i + j*4];
}
}
model->mInvBindMatrix.push_back(mat);
}
}
}
}
}
//grab raw position array
domVertices* verts = mesh->getVertices();
if (verts)
{
domInputLocal_Array& inputs = verts->getInput_array();
for (size_t i = 0; i < inputs.getCount() && model->mPosition.empty(); ++i)
{
if (strcmp(inputs[i]->getSemantic(), COMMON_PROFILE_INPUT_POSITION) == 0)
{
domSource* pos_source = daeSafeCast<domSource>(inputs[i]->getSource().getElement());
if (pos_source)
{
domFloat_array* pos_array = pos_source->getFloat_array();
if (pos_array)
{
domListOfFloats& pos = pos_array->getValue();
for (size_t j = 0; j < pos.getCount(); j += 3)
{
if (pos.getCount() <= j+2)
{
llerrs << "WTF?" << llendl;
}
LLVector3 v(pos[j], pos[j+1], pos[j+2]);
//transform from COLLADA space to volume space
v = v * inverse_normalized_transformation;
model->mPosition.push_back(v);
}
}
}
}
}
}
//grab skin weights array
domSkin::domVertex_weights* weights = skin->getVertex_weights();
if (weights)
{
domInputLocalOffset_Array& inputs = weights->getInput_array();
domFloat_array* vertex_weights = NULL;
for (size_t i = 0; i < inputs.getCount(); ++i)
{
if (strcmp(inputs[i]->getSemantic(), COMMON_PROFILE_INPUT_WEIGHT) == 0)
{
domSource* weight_source = daeSafeCast<domSource>(inputs[i]->getSource().getElement());
if (weight_source)
{
vertex_weights = weight_source->getFloat_array();
}
}
}
if (vertex_weights)
{
domListOfFloats& w = vertex_weights->getValue();
domListOfUInts& vcount = weights->getVcount()->getValue();
domListOfInts& v = weights->getV()->getValue();
U32 c_idx = 0;
for (size_t vc_idx = 0; vc_idx < vcount.getCount(); ++vc_idx)
{ //for each vertex
daeUInt count = vcount[vc_idx];
//create list of weights that influence this vertex
LLModel::weight_list weight_list;
for (daeUInt i = 0; i < count; ++i)
{ //for each weight
daeInt joint_idx = v[c_idx++];
daeInt weight_idx = v[c_idx++];
if (joint_idx == -1)
{
//ignore bindings to bind_shape_matrix
continue;
}
F32 weight_value = w[weight_idx];
weight_list.push_back(LLModel::JointWeight(joint_idx, weight_value));
}
//sort by joint weight
std::sort(weight_list.begin(), weight_list.end(), LLModel::CompareWeightGreater());
std::vector<LLModel::JointWeight> wght;
F32 total = 0.f;
for (U32 i = 0; i < llmin((U32) 4, (U32) weight_list.size()); ++i)
{ //take up to 4 most significant weights
if (weight_list[i].mWeight > 0.f)
{
wght.push_back( weight_list[i] );
total += weight_list[i].mWeight;
}
}
F32 scale = 1.f/total;
if (scale != 1.f)
{ //normalize weights
for (U32 i = 0; i < wght.size(); ++i)
{
wght[i].mWeight *= scale;
}
}
model->mSkinWeights[model->mPosition[vc_idx]] = wght;
}
//add instance to scene for this model
LLMatrix4 transform;
std::vector<LLImportMaterial> materials;
materials.resize(model->getNumVolumeFaces());
mScene[transform].push_back(LLModelInstance(model, transform, materials));
stretch_extents(model, transform, mExtents[0], mExtents[1], mFirstTransform);
}
}
}
}
}
}
}
daeElement* scene = root->getDescendant("visual_scene");
if (!scene)
{
llwarns << "document has no visual_scene" << llendl;
return;
}
processElement(scene);
mPreview->loadModelCallback(mLod);
}
}
void LLModelLoader::processElement(daeElement* element)
{
LLMatrix4 saved_transform = mTransform;
domTranslate* translate = daeSafeCast<domTranslate>(element);
if (translate)
{
domFloat3 dom_value = translate->getValue();
LLMatrix4 translation;
translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
translation *= mTransform;
mTransform = translation;
}
domRotate* rotate = daeSafeCast<domRotate>(element);
if (rotate)
{
domFloat4 dom_value = rotate->getValue();
LLMatrix4 rotation;
rotation.initRotTrans(dom_value[3] * DEG_TO_RAD, LLVector3(dom_value[0], dom_value[1], dom_value[2]), LLVector3(0, 0, 0));
rotation *= mTransform;
mTransform = rotation;
}
domScale* scale = daeSafeCast<domScale>(element);
if (scale)
{
domFloat3 dom_value = scale->getValue();
LLMatrix4 scaling;
scaling.initScale(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
scaling *= mTransform;
mTransform = scaling;
}
domMatrix* matrix = daeSafeCast<domMatrix>(element);
if (matrix)
{
domFloat4x4 dom_value = matrix->getValue();
LLMatrix4 matrix_transform;
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
matrix_transform.mMatrix[i][j] = dom_value[i + j*4];
}
}
matrix_transform *= mTransform;
mTransform = matrix_transform;
}
domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
if (instance_geo)
{
domGeometry* geo = daeSafeCast<domGeometry>(instance_geo->getUrl().getElement());
if (geo)
{
domMesh* mesh = daeSafeCast<domMesh>(geo->getDescendant(daeElement::matchType(domMesh::ID())));
if (mesh)
{
LLModel* model = mModel[mesh];
if (model)
{
LLMatrix4 transformation = mTransform;
std::vector<LLImportMaterial> materials = getMaterials(model, instance_geo);
// adjust the transformation to compensate for mesh normalization
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
model->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
LLMatrix4 mesh_translation;
mesh_translation.setTranslation(mesh_translation_vector);
mesh_translation *= transformation;
transformation = mesh_translation;
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= transformation;
transformation = mesh_scale;
mScene[transformation].push_back(LLModelInstance(model, transformation, materials));
stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);
}
}
}
}
domInstance_node* instance_node = daeSafeCast<domInstance_node>(element);
if (instance_node)
{
daeElement* instance = instance_node->getUrl().getElement();
if (instance)
{
processElement(instance);
}
}
//process children
daeTArray< daeSmartRef<daeElement> > children = element->getChildren();
for (S32 i = 0; i < children.getCount(); i++)
{
processElement(children[i]);
}
domNode* node = daeSafeCast<domNode>(element);
if (node)
{ //this element was a node, restore transform before processiing siblings
mTransform = saved_transform;
}
}
std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domInstance_geometry* instance_geo)
{
std::vector<LLImportMaterial> materials;
for (int i = 0; i < model->mMaterialList.size(); i++)
{
LLImportMaterial import_material;
domInstance_material* instance_mat = NULL;
domBind_material::domTechnique_common* technique =
daeSafeCast<domBind_material::domTechnique_common>(instance_geo->getDescendant(daeElement::matchType(domBind_material::domTechnique_common::ID())));
if (technique)
{
daeTArray< daeSmartRef<domInstance_material> > inst_materials = technique->getChildrenByType<domInstance_material>();
for (int j = 0; j < inst_materials.getCount(); j++)
{
std::string symbol(inst_materials[j]->getSymbol());
if (symbol == model->mMaterialList[i]) // found the binding
{
instance_mat = inst_materials[j];
}
}
}
if (instance_mat)
{
domMaterial* material = daeSafeCast<domMaterial>(instance_mat->getTarget().getElement());
if (material)
{
domInstance_effect* instance_effect =
daeSafeCast<domInstance_effect>(material->getDescendant(daeElement::matchType(domInstance_effect::ID())));
if (instance_effect)
{
domEffect* effect = daeSafeCast<domEffect>(instance_effect->getUrl().getElement());
if (effect)
{
domProfile_COMMON* profile =
daeSafeCast<domProfile_COMMON>(effect->getDescendant(daeElement::matchType(domProfile_COMMON::ID())));
if (profile)
{
import_material = profileToMaterial(profile);
}
}
}
}
}
materials.push_back(import_material);
}
return materials;
}
LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
{
LLImportMaterial mat;
mat.mFullbright = FALSE;
daeElement* diffuse = material->getDescendant("diffuse");
if (diffuse)
{
domCommon_color_or_texture_type_complexType::domTexture* texture =
daeSafeCast<domCommon_color_or_texture_type_complexType::domTexture>(diffuse->getDescendant("texture"));
if (texture)
{
domCommon_newparam_type_Array newparams = material->getNewparam_array();
for (S32 i = 0; i < newparams.getCount(); i++)
{
domFx_surface_common* surface = newparams[i]->getSurface();
if (surface)
{
domFx_surface_init_common* init = surface->getFx_surface_init_common();
if (init)
{
domFx_surface_init_from_common_Array init_from = init->getInit_from_array();
if (init_from.getCount() > i)
{
domImage* image = daeSafeCast<domImage>(init_from[i]->getValue().getElement());
if (image)
{
// we only support init_from now - embedded data will come later
domImage::domInit_from* init = image->getInit_from();
if (init)
{
std::string filename = cdom::uriToNativePath(init->getValue().str());
mat.mDiffuseMap = LLViewerTextureManager::getFetchedTextureFromUrl("file://" + filename, TRUE, LLViewerTexture::BOOST_PREVIEW);
mat.mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, this->mPreview, NULL, FALSE);
mat.mDiffuseMap->forceToSaveRawImage();
mat.mDiffuseMapFilename = filename;
mat.mDiffuseMapLabel = getElementLabel(material);
}
}
}
}
}
}
}
domCommon_color_or_texture_type_complexType::domColor* color =
daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(diffuse->getDescendant("color"));
if (color)
{
domFx_color_common domfx_color = color->getValue();
LLColor4 value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]);
mat.mDiffuseColor = value;
}
}
daeElement* emission = material->getDescendant("emission");
if (emission)
{
LLColor4 emission_color = getDaeColor(emission);
if (((emission_color[0] + emission_color[1] + emission_color[2]) / 3.0) > 0.25)
{
mat.mFullbright = TRUE;
}
}
return mat;
}
// try to get a decent label for this element
std::string LLModelLoader::getElementLabel(daeElement *element)
{
// if we have a name attribute, use it
std::string name = element->getAttribute("name");
if (name.length())
{
return name;
}
// if we have an ID attribute, use it
if (element->getID())
{
return std::string(element->getID());
}
// if we have a parent, use it
daeElement* parent = element->getParent();
if (parent)
{
// if parent has a name, use it
std::string name = parent->getAttribute("name");
if (name.length())
{
return name;
}
// if parent has an ID, use it
if (parent->getID())
{
return std::string(parent->getID());
}
}
// try to use our type
daeString element_name = element->getElementName();
if (element_name)
{
return std::string(element_name);
}
// if all else fails, use "object"
return std::string("object");
}
LLColor4 LLModelLoader::getDaeColor(daeElement* element)
{
LLColor4 value;
domCommon_color_or_texture_type_complexType::domColor* color =
daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(element->getDescendant("color"));
if (color)
{
domFx_color_common domfx_color = color->getValue();
value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]);
}
return value;
}
//-----------------------------------------------------------------------------
// LLModelPreview
//-----------------------------------------------------------------------------
LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloaterModelPreview* fmp)
: LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE), LLMutex(NULL)
{
mNeedsUpdate = TRUE;
mCameraDistance = 0.f;
mCameraYaw = 0.f;
mCameraPitch = 0.f;
mCameraZoom = 1.f;
mTextureName = 0;
mPreviewLOD = 3;
mModelLoader = NULL;
mDirty = false;
mLODMode[0] = 0;
for (U32 i = 1; i < LLModel::NUM_LODS; i++)
{
mLODMode[i] = 1;
mLimit[i] = 0;
}
mFMP = fmp;
glodInit();
}
LLModelPreview::~LLModelPreview()
{
if (mModelLoader)
{
delete mModelLoader;
mModelLoader = NULL;
}
//*HACK : *TODO : turn this back on when we understand why this crashes
//glodShutdown();
}
U32 LLModelPreview::calcResourceCost()
{
rebuildUploadData();
U32 cost = 0;
std::set<LLModel*> accounted;
U32 num_points = 0;
U32 num_hulls = 0;
for (U32 i = 0; i < mUploadData.size(); ++i)
{
LLModelInstance& instance = mUploadData[i];
if (accounted.find(instance.mModel) == accounted.end())
{
accounted.insert(instance.mModel);
LLModel::physics_shape& physics_shape = instance.mLOD[LLModel::LOD_PHYSICS] ? instance.mLOD[LLModel::LOD_PHYSICS]->mPhysicsShape : instance.mModel->mPhysicsShape;
LLSD ret = LLModel::writeModel("",
instance.mLOD[4],
instance.mLOD[3],
instance.mLOD[2],
instance.mLOD[1],
instance.mLOD[0],
physics_shape,
TRUE);
cost += gMeshRepo.calcResourceCost(ret);
num_hulls += physics_shape.size();
for (U32 i = 0; i < physics_shape.size(); ++i)
{
num_points += physics_shape[i].size();
}
}
}
mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[HULLS]", llformat("%d",num_hulls));
mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[POINTS]", llformat("%d",num_points));
updateStatusMessages();
return cost;
}
void LLModelPreview::rebuildUploadData()
{
mUploadData.clear();
mTextureSet.clear();
//fill uploaddata instance vectors from scene data
for (LLModelLoader::scene::iterator iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter)
{ //for each transform in scene
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ //for each instance with said transform applied
LLModelInstance& instance = *model_iter;
LLModel* base_model = instance.mModel;
S32 idx = 0;
for (idx = 0; idx < mBaseModel.size(); ++idx)
{ //find reference instance for this model
if (mBaseModel[idx] == base_model)
{
break;
}
}
for (U32 i = 0; i < LLModel::NUM_LODS; i++)
{ //fill LOD slots based on reference model index
if (!mModel[i].empty())
{
instance.mLOD[i] = mModel[i][idx];
}
else
{
instance.mLOD[i] = NULL;
}
}
mUploadData.push_back(instance);
}
}
}
void LLModelPreview::loadModel(std::string filename, S32 lod)
{
LLMutexLock lock(this);
if (mModelLoader)
{
delete mModelLoader;
mModelLoader = NULL;
}
if (filename.empty() && mBaseModel.empty())
{
mFMP->closeFloater(false);
return;
}
if (lod == 3 && !mGroup.empty())
{
for (std::map<LLModel*, U32>::iterator iter = mGroup.begin(); iter != mGroup.end(); ++iter)
{
glodDeleteGroup(iter->second);
stop_gloderror();
}
for (std::map<LLModel*, U32>::iterator iter = mObject.begin(); iter != mObject.end(); ++iter)
{
glodDeleteObject(iter->second);
stop_gloderror();
}
mGroup.clear();
mObject.clear();
}
mModelLoader = new LLModelLoader(filename, lod, this);
mModelLoader->start();
mFMP->childSetTextArg("status", "[STATUS]", mFMP->getString("status_reading_file"));
if (mFMP->childGetValue("description_form").asString().empty())
{
std::string name = gDirUtilp->getBaseFileName(filename, true);
mFMP->childSetValue("description_form", name);
}
mFMP->openFloater();
}
void LLModelPreview::clearIncompatible(S32 lod)
{
for (U32 i = 0; i <= LLModel::LOD_HIGH; i++)
{ //clear out any entries that aren't compatible with this model
if (i != lod)
{
if (mModel[i].size() != mModel[lod].size())
{
mModel[i].clear();
mScene[i].clear();
mVertexBuffer[i].clear();
if (i == LLModel::LOD_HIGH)
{
mBaseModel = mModel[lod];
mBaseScene = mScene[lod];
mVertexBuffer[5].clear();
}
}
}
}
}
void LLModelPreview::loadModelCallback(S32 lod)
{ //NOT the main thread
LLMutexLock lock(this);
if (!mModelLoader)
{
return;
}
mModel[lod] = mModelLoader->mModelList;
mScene[lod] = mModelLoader->mScene;
mVertexBuffer[lod].clear();
setPreviewLOD(lod);
if (lod == LLModel::LOD_HIGH)
{ //save a copy of the highest LOD for automatic LOD manipulation
mBaseModel = mModel[lod];
mBaseScene = mScene[lod];
mVertexBuffer[5].clear();
//mModel[lod] = NULL;
}
clearIncompatible(lod);
mDirty = true;
mPreviewTarget = (mModelLoader->mExtents[0] + mModelLoader->mExtents[1]) * 0.5f;
mPreviewScale = (mModelLoader->mExtents[1] - mModelLoader->mExtents[0]) * 0.5f;
setPreviewTarget(mPreviewScale.magVec()*2.f);
mFMP->mLoading = FALSE;
refresh();
}
void LLModelPreview::smoothNormals()
{
S32 which_lod = mPreviewLOD;
if (which_lod > 4 || which_lod < 0 ||
mModel[which_lod].empty())
{
return;
}
F32 angle_cutoff = mFMP->childGetValue("edge threshold").asReal();
angle_cutoff *= DEG_TO_RAD;
if (which_lod == 3 && !mBaseModel.empty())
{
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{
(*iter)->smoothNormals(angle_cutoff);
}
mVertexBuffer[5].clear();
}
for (LLModelLoader::model_list::iterator iter = mModel[which_lod].begin(); iter != mModel[which_lod].end(); ++iter)
{
(*iter)->smoothNormals(angle_cutoff);
}
mVertexBuffer[which_lod].clear();
refresh();
}
void LLModelPreview::consolidate()
{
std::map<LLImportMaterial, std::vector<LLModelInstance> > composite;
LLMatrix4 identity;
//bake out each node in current scene to composite
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{ //for each transform in current scene
LLMatrix4 mat = iter->first;
glh::matrix4f inv_trans = glh::matrix4f((F32*) mat.mMatrix).inverse().transpose();
LLMatrix4 norm_mat(inv_trans.m);
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ //for each instance with that transform
LLModelInstance& source_instance = *model_iter;
LLModel* source = source_instance.mModel;
if (!validate_model(source))
{
llerrs << "Invalid model found!" << llendl;
}
for (S32 i = 0; i < source->getNumVolumeFaces(); ++i)
{ //for each face in instance
const LLVolumeFace& src_face = source->getVolumeFace(i);
LLImportMaterial& source_material = source_instance.mMaterial[i];
//get model in composite that is composite for this material
LLModel* model = NULL;
if (composite.find(source_material) != composite.end())
{
model = composite[source_material].rbegin()->mModel;
if (model->getVolumeFace(0).mNumVertices + src_face.mNumVertices > 65535)
{
model = NULL;
}
}
if (model == NULL)
{ //no model found, make new model
std::vector<LLImportMaterial> materials;
materials.push_back(source_material);
LLVolumeParams volume_params;
volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
model = new LLModel(volume_params, 0.f);
model->mLabel = source->mLabel;
model->setNumVolumeFaces(0);
composite[source_material].push_back(LLModelInstance(model, identity, materials));
}
model->appendFace(src_face, source->mMaterialList[i], mat, norm_mat);
}
}
}
//condense composite into as few LLModel instances as possible
LLModelLoader::model_list new_model;
std::vector<LLModelInstance> instance_list;
LLVolumeParams volume_params;
volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
std::vector<LLImportMaterial> empty_material;
LLModelInstance cur_instance(new LLModel(volume_params, 0.f), identity, empty_material);
cur_instance.mModel->setNumVolumeFaces(0);
BOOL first_transform = TRUE;
LLModelLoader::scene new_scene;
LLVector3 min,max;
for (std::map<LLImportMaterial, std::vector<LLModelInstance> >::iterator iter = composite.begin();
iter != composite.end();
++iter)
{
std::map<LLImportMaterial, std::vector<LLModelInstance> >::iterator next_iter = iter; ++next_iter;
for (std::vector<LLModelInstance>::iterator instance_iter = iter->second.begin();
instance_iter != iter->second.end();
++instance_iter)
{
LLModel* source = instance_iter->mModel;
if (instance_iter->mMaterial.size() != 1)
{
llerrs << "WTF?" << llendl;
}
if (source->getNumVolumeFaces() != 1)
{
llerrs << "WTF?" << llendl;
}
if (source->mMaterialList.size() != 1)
{
llerrs << "WTF?" << llendl;
}
cur_instance.mModel->addFace(source->getVolumeFace(0));
cur_instance.mMaterial.push_back(instance_iter->mMaterial[0]);
cur_instance.mModel->mMaterialList.push_back(source->mMaterialList[0]);
BOOL last_model = FALSE;
std::vector<LLModelInstance>::iterator next_instance = instance_iter; ++next_instance;
if (next_iter == composite.end() &&
next_instance == iter->second.end())
{
last_model = TRUE;
}
if (last_model || cur_instance.mModel->getNumVolumeFaces() >= MAX_MODEL_FACES)
{
cur_instance.mModel->mLabel = source->mLabel;
cur_instance.mModel->optimizeVolumeFaces();
cur_instance.mModel->normalizeVolumeFaces();
if (!validate_model(cur_instance.mModel))
{
llerrs << "Invalid model detected." << llendl;
}
new_model.push_back(cur_instance.mModel);
LLMatrix4 transformation = LLMatrix4();
// adjust the transformation to compensate for mesh normalization
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
cur_instance.mModel->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
LLMatrix4 mesh_translation;
mesh_translation.setTranslation(mesh_translation_vector);
mesh_translation *= transformation;
transformation = mesh_translation;
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= transformation;
transformation = mesh_scale;
cur_instance.mTransform = transformation;
new_scene[transformation].push_back(cur_instance);
stretch_extents(cur_instance.mModel, transformation, min, max, first_transform);
if (!last_model)
{
cur_instance = LLModelInstance(new LLModel(volume_params, 0.f), identity, empty_material);
cur_instance.mModel->setNumVolumeFaces(0);
}
}
}
}
mScene[mPreviewLOD] = new_scene;
mModel[mPreviewLOD] = new_model;
mVertexBuffer[mPreviewLOD].clear();
if (mPreviewLOD == LLModel::LOD_HIGH)
{
mBaseScene = new_scene;
mBaseModel = new_model;
mVertexBuffer[5].clear();
}
mPreviewTarget = (min+max)*0.5f;
mPreviewScale = (max-min)*0.5f;
setPreviewTarget(mPreviewScale.magVec()*2.f);
clearIncompatible(mPreviewLOD);
mResourceCost = calcResourceCost();
refresh();
}
void LLModelPreview::scrubMaterials()
{
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{ //for each transform in current scene
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ //for each instance with that transform
LLModelInstance& source_instance = *model_iter;
LLModel* source = source_instance.mModel;
for (S32 i = 0; i < source->getNumVolumeFaces(); ++i)
{ //for each face in instance
LLImportMaterial& source_material = source_instance.mMaterial[i];
//clear material info
source_material.mDiffuseColor = LLColor4(1,1,1,1);
source_material.mDiffuseMap = NULL;
source_material.mDiffuseMapFilename.clear();
source_material.mDiffuseMapLabel.clear();
source_material.mFullbright = false;
}
}
}
mVertexBuffer[mPreviewLOD].clear();
if (mPreviewLOD == LLModel::LOD_HIGH)
{
mBaseScene = mScene[mPreviewLOD];
mBaseModel = mModel[mPreviewLOD];
mVertexBuffer[5].clear();
}
mResourceCost = calcResourceCost();
refresh();
}
void LLModelPreview::genLODs(S32 which_lod)
{
if (mBaseModel.empty())
{
return;
}
LLVertexBuffer::unbind();
stop_gloderror();
static U32 cur_name = 1;
S32 limit = -1;
if (which_lod != -1)
{
limit = mLimit[which_lod];
}
U32 triangle_count = 0;
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{
LLModel* mdl = *iter;
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
triangle_count += mdl->getVolumeFace(i).mNumIndices/3;
}
}
U32 base_triangle_count = triangle_count;
U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{ //build GLOD objects for each model in base model list
LLModel* mdl = *iter;
if (mGroup[mdl] == 0)
{
mGroup[mdl] = cur_name++;
mObject[mdl] = cur_name++;
glodNewGroup(mGroup[mdl]);
stop_gloderror();
glodGroupParameteri(mGroup[mdl], GLOD_ADAPT_MODE, GLOD_TRIANGLE_BUDGET);
stop_gloderror();
glodGroupParameteri(mGroup[mdl], GLOD_ERROR_MODE, GLOD_OBJECT_SPACE_ERROR);
stop_gloderror();
glodGroupParameterf(mGroup[mdl], GLOD_OBJECT_SPACE_ERROR_THRESHOLD, 0.025f);
stop_gloderror();
glodNewObject(mObject[mdl], mGroup[mdl], GLOD_DISCRETE);
stop_gloderror();
if (iter == mBaseModel.begin() && !mdl->mSkinWeights.empty())
{ //regenerate vertex buffer for skinned models to prevent animation feedback during LOD generation
mVertexBuffer[5].clear();
}
if (mVertexBuffer[5].empty())
{
genBuffers(5);
}
U32 tri_count = 0;
for (U32 i = 0; i < mVertexBuffer[5][mdl].size(); ++i)
{
mVertexBuffer[5][mdl][i]->setBuffer(type_mask);
U32 num_indices = mVertexBuffer[5][mdl][i]->getNumIndices();
if (num_indices > 2)
{
glodInsertElements(mObject[mdl], i, GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, mVertexBuffer[5][mdl][i]->getIndicesPointer(), 0, 0.f);
}
tri_count += num_indices/3;
stop_gloderror();
}
//store what percentage of total model (in terms of triangle count) this model makes up
mPercentage[mdl] = (F32) tri_count / (F32) base_triangle_count;
//build glodobject
glodBuildObject(mObject[mdl]);
if (stop_gloderror())
{
glodDeleteGroup(mGroup[mdl]);
stop_gloderror();
glodDeleteObject(mObject[mdl]);
stop_gloderror();
mGroup[mdl] = 0;
mObject[mdl] = 0;
if (which_lod == -1)
{
mModel[LLModel::LOD_HIGH] = mBaseModel;
}
return;
}
}
if (which_lod == -1 || mLODMode[which_lod] == 1)
{
//generating LODs for all entries, or this entry has a triangle budget
glodGroupParameteri(mGroup[mdl], GLOD_ADAPT_MODE, GLOD_TRIANGLE_BUDGET);
stop_gloderror();
}
else
{
//this entry uses error mode
glodGroupParameteri(mGroup[mdl], GLOD_ADAPT_MODE, GLOD_OBJECT_SPACE_ERROR);
stop_gloderror();
}
if (which_lod != -1 && mLODMode[which_lod] == 2)
{
glodGroupParameterf(mGroup[mdl], GLOD_OBJECT_SPACE_ERROR_THRESHOLD, llmax(limit/100.f, 0.01f));
stop_gloderror();
}
else
{
glodGroupParameterf(mGroup[mdl], GLOD_OBJECT_SPACE_ERROR_THRESHOLD, 0.025f);
stop_gloderror();
}
}
S32 start = LLModel::LOD_HIGH;
S32 end = 0;
BOOL error_mode = FALSE;
if (which_lod != -1)
{
start = end = which_lod;
if (mLODMode[which_lod] == 2)
{
error_mode = TRUE;
}
}
for (S32 lod = start; lod >= end; --lod)
{
if (!error_mode)
{
if (which_lod == -1)
{
if (lod < start)
{
triangle_count /= 3;
}
}
else
{
triangle_count = limit;
}
}
mModel[lod].clear();
mModel[lod].resize(mBaseModel.size());
mVertexBuffer[lod].clear();
U32 actual_tris = 0;
U32 actual_verts = 0;
U32 submeshes = 0;
for (U32 mdl_idx = 0; mdl_idx < mBaseModel.size(); ++mdl_idx)
{
LLModel* base = mBaseModel[mdl_idx];
U32 target_count = U32(mPercentage[base]*triangle_count);
if (error_mode)
{
target_count = base->getNumTriangles();
}
if (target_count < 4)
{
target_count = 4;
}
if (which_lod == -1 || mLODMode[which_lod] == 1)
{
glodGroupParameteri(mGroup[base], GLOD_MAX_TRIANGLES, target_count);
stop_gloderror();
}
glodAdaptGroup(mGroup[base]);
stop_gloderror();
GLint patch_count = 0;
glodGetObjectParameteriv(mObject[base], GLOD_NUM_PATCHES, &patch_count);
stop_gloderror();
LLVolumeParams volume_params;
volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
mModel[lod][mdl_idx] = new LLModel(volume_params, 0.f);
GLint* sizes = new GLint[patch_count*2];
glodGetObjectParameteriv(mObject[base], GLOD_PATCH_SIZES, sizes);
stop_gloderror();
GLint* names = new GLint[patch_count];
glodGetObjectParameteriv(mObject[base], GLOD_PATCH_NAMES, names);
stop_gloderror();
mModel[lod][mdl_idx]->setNumVolumeFaces(patch_count);
LLModel* target_model = mModel[lod][mdl_idx];
for (GLint i = 0; i < patch_count; ++i)
{
LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(type_mask, 0);
if (sizes[i*2+1] > 0 && sizes[i*2] > 0)
{
buff->allocateBuffer(sizes[i*2+1], sizes[i*2], true);
buff->setBuffer(type_mask);
glodFillElements(mObject[base], names[i], GL_UNSIGNED_SHORT, buff->getIndicesPointer());
stop_gloderror();
}
else
{ //this face was eliminated, create a dummy triangle (one vertex, 3 indices, all 0)
buff->allocateBuffer(1, 3, true);
memset(buff->getMappedData(), 0, buff->getSize());
memset(buff->getIndicesPointer(), 0, buff->getIndicesSize());
}
buff->validateRange(0, buff->getNumVerts()-1, buff->getNumIndices(), 0);
LLStrider<LLVector3> pos;
LLStrider<LLVector3> norm;
LLStrider<LLVector2> tc;
LLStrider<U16> index;
buff->getVertexStrider(pos);
buff->getNormalStrider(norm);
buff->getTexCoord0Strider(tc);
buff->getIndexStrider(index);
target_model->setVolumeFaceData(names[i], pos, norm, tc, index, buff->getNumVerts(), buff->getNumIndices());
actual_tris += buff->getNumIndices()/3;
actual_verts += buff->getNumVerts();
++submeshes;
if (!validate_face(target_model->getVolumeFace(names[i])))
{
llerrs << "Invalid face generated during LOD generation." << llendl;
}
}
//blind copy skin weights and just take closest skin weight to point on
//decimated mesh for now (auto-generating LODs with skin weights is still a bit
//of an open problem).
target_model->mPosition = base->mPosition;
target_model->mSkinWeights = base->mSkinWeights;
target_model->mJointMap = base->mJointMap;
target_model->mJointList = base->mJointList;
target_model->mInvBindMatrix = base->mInvBindMatrix;
target_model->mBindShapeMatrix = base->mBindShapeMatrix;
if (!validate_model(target_model))
{
llerrs << "Invalid model generated when creating LODs" << llendl;
}
delete [] sizes;
delete [] names;
}
//rebuild scene based on mBaseScene
mScene[lod].clear();
mScene[lod] = mBaseScene;
for (U32 i = 0; i < mBaseModel.size(); ++i)
{
LLModel* mdl = mBaseModel[i];
LLModel* target = mModel[lod][i];
if (target)
{
for (LLModelLoader::scene::iterator iter = mScene[lod].begin(); iter != mScene[lod].end(); ++iter)
{
for (U32 j = 0; j < iter->second.size(); ++j)
{
if (iter->second[j].mModel == mdl)
{
iter->second[j].mModel = target;
}
}
}
}
}
mResourceCost = calcResourceCost();
}
}
void LLModelPreview::updateStatusMessages()
{
//triangle/vertex/submesh count for each mesh asset for each lod
std::vector<S32> tris[LLModel::NUM_LODS];
std::vector<S32> verts[LLModel::NUM_LODS];
std::vector<S32> submeshes[LLModel::NUM_LODS];
//total triangle/vertex/submesh count for each lod
S32 total_tris[LLModel::NUM_LODS];
S32 total_verts[LLModel::NUM_LODS];
S32 total_submeshes[LLModel::NUM_LODS];
for (S32 lod = 0; lod <= LLModel::LOD_HIGH; ++lod)
{
//initialize total for this lod to 0
total_tris[lod] = total_verts[lod] = total_submeshes[lod] = 0;
for (U32 i = 0; i < mModel[lod].size(); ++i)
{ //for each model in the lod
S32 cur_tris = 0;
S32 cur_verts = 0;
S32 cur_submeshes = mModel[lod][i]->getNumVolumeFaces();
for (S32 j = 0; j < cur_submeshes; ++j)
{ //for each submesh (face), add triangles and vertices to current total
const LLVolumeFace& face = mModel[lod][i]->getVolumeFace(j);
cur_tris += face.mNumIndices/3;
cur_verts += face.mNumVertices;
}
//add this model to the lod total
total_tris[lod] += cur_tris;
total_verts[lod] += cur_verts;
total_submeshes[lod] += cur_submeshes;
//store this model's counts to asset data
tris[lod].push_back(cur_tris);
verts[lod].push_back(cur_verts);
submeshes[lod].push_back(cur_submeshes);
}
}
std::string upload_message;
for (S32 lod = 0; lod <= LLModel::LOD_HIGH; ++lod)
{
mFMP->childSetTextArg(info_name[lod], "[TRIANGLES]", llformat("%d", total_tris[lod]));
mFMP->childSetTextArg(info_name[lod], "[VERTICES]", llformat("%d", total_verts[lod]));
mFMP->childSetTextArg(info_name[lod], "[SUBMESHES]", llformat("%d", total_submeshes[lod]));
std::string message = "good";
const U32 lod_high = LLModel::LOD_HIGH;
if (lod != lod_high)
{
if (total_submeshes[lod] == 0)
{ //no model loaded for this lod, see if one is required
for (U32 i = 0; i < verts[lod_high].size(); ++i)
{
const F32 ratio = 0.5f;
const S32 required_verts = 128;
F32 scaler = powf(ratio, lod_high-lod);
S32 max_verts = (S32)(verts[lod_high][i]*scaler);
if (max_verts > required_verts)
{ //some model in this slot might have more than 128 vertices
//if any model higher up the chain has more than 128 vertices,
// lod is required here
for (S32 j = lod+1; j <= LLModel::LOD_HIGH; ++j)
{
if (verts[j].size() > i && verts[j][i] > 128)
{
message = "required";
upload_message = "missing_lod";
}
}
}
}
}
else if (total_submeshes[lod] != total_submeshes[lod_high])
{
message = "mesh_mismatch";
upload_message = "bad_lod";
}
else if (tris[lod].size() != tris[lod_high].size())
{
message = "model_mismatch";
upload_message = "bad_lod";
}
else
{
for (U32 i = 0; i < verts[lod].size(); ++i)
{
const F32 ratio = 0.5f;
F32 scaler = powf(ratio, lod_high-lod);
S32 max_verts = (S32)(verts[lod_high][i]*scaler);
if (verts[lod][i] > max_verts)
{
message = "too_heavy";
upload_message = "bad_lod";
}
}
}
}
mFMP->childSetTextArg(info_name[lod], "[MESSAGE]", mFMP->getString(message));
}
if (upload_message.empty())
{
mFMP->childSetTextArg("upload_message", "[MESSAGE]", std::string(""));
mFMP->childEnable("ok_btn");
}
else
{
mFMP->childSetTextArg("upload_message", "[MESSAGE]", mFMP->getString(upload_message));
mFMP->childDisable("ok_btn");
}
}
void LLModelPreview::setPreviewTarget(F32 distance)
{
mCameraDistance = distance;
mCameraZoom = 1.f;
mCameraPitch = 0.f;
mCameraYaw = 0.f;
mCameraOffset.clearVec();
}
void LLModelPreview::genBuffers(S32 lod)
{
U32 tri_count = 0;
U32 vertex_count = 0;
U32 mesh_count = 0;
LLModelLoader::model_list* model = NULL;
if (lod < 0 || lod > 4)
{
model = &mBaseModel;
lod = 5;
}
else
{
model = &(mModel[lod]);
}
if (!mVertexBuffer[lod].empty())
{
mVertexBuffer[lod].clear();
}
mVertexBuffer[lod].clear();
LLModelLoader::model_list::iterator base_iter = mBaseModel.begin();
for (LLModelLoader::model_list::iterator iter = model->begin(); iter != model->end(); ++iter)
{
LLModel* mdl = *iter;
if (!mdl)
{
continue;
}
LLModel* base_mdl = *base_iter;
base_iter++;
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
const LLVolumeFace &vf = mdl->getVolumeFace(i);
U32 num_vertices = vf.mNumVertices;
U32 num_indices = vf.mNumIndices;
if (!num_vertices || ! num_indices)
{
continue;
}
LLVertexBuffer* vb = NULL;
bool skinned = !mdl->mSkinWeights.empty();
U32 mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
if (skinned)
{
mask |= LLVertexBuffer::MAP_WEIGHT4;
}
vb = new LLVertexBuffer(mask, 0);
vb->allocateBuffer(num_vertices, num_indices, TRUE);
LLStrider<LLVector3> vertex_strider;
LLStrider<LLVector3> normal_strider;
LLStrider<LLVector2> tc_strider;
LLStrider<U16> index_strider;
LLStrider<LLVector4> weights_strider;
vb->getVertexStrider(vertex_strider);
vb->getNormalStrider(normal_strider);
vb->getTexCoord0Strider(tc_strider);
vb->getIndexStrider(index_strider);
if (skinned)
{
vb->getWeight4Strider(weights_strider);
}
LLVector4a::memcpyNonAliased16((F32*) vertex_strider.get(), (F32*) vf.mPositions, num_vertices*4*sizeof(F32));
LLVector4a::memcpyNonAliased16((F32*) tc_strider.get(), (F32*) vf.mTexCoords, num_vertices*2*sizeof(F32));
LLVector4a::memcpyNonAliased16((F32*) normal_strider.get(), (F32*) vf.mNormals, num_vertices*4*sizeof(F32));
if (skinned)
{
// build vertices and normals
for (U32 i = 0; i < num_vertices; i++)
{
//find closest weight to vf.mVertices[i].mPosition
LLVector3 pos(vf.mPositions[i].getF32ptr());
LLModel::weight_list weight_list = base_mdl->getJointInfluences(pos);
LLVector4 w(0,0,0,0);
if (weight_list.size() > 4)
{
llerrs << "WTF?" << llendl;
}
for (U32 i = 0; i < weight_list.size(); ++i)
{
F32 wght = llmin(weight_list[i].mWeight, 0.999999f);
F32 joint = (F32) weight_list[i].mJointIdx;
w.mV[i] = joint + wght;
}
*(weights_strider++) = w;
}
}
// build indices
for (U32 i = 0; i < num_indices; i++)
{
*(index_strider++) = vf.mIndices[i];
}
mVertexBuffer[lod][mdl].push_back(vb);
vertex_count += num_vertices;
tri_count += num_indices/3;
++mesh_count;
}
}
if (lod == 4)
{
for (U32 i = 0; i < 4; i++)
{
LLSpinCtrl* lim = mFMP->getChild<LLSpinCtrl>(limit_name[i], TRUE);
lim->setMaxValue(tri_count);
}
}
}
void LLModelPreview::update()
{
if (mDirty)
{
mDirty = false;
mResourceCost = calcResourceCost();
}
}
//-----------------------------------------------------------------------------
// render()
//-----------------------------------------------------------------------------
BOOL LLModelPreview::render()
{
LLMutexLock lock(this);
mNeedsUpdate = FALSE;
S32 width = getWidth();
S32 height = getHeight();
LLGLSUIDefault def;
LLGLDisable no_blend(GL_BLEND);
LLGLEnable cull(GL_CULL_FACE);
LLGLDepthTest depth(GL_TRUE);
LLGLDisable fog(GL_FOG);
glMatrixMode(GL_PROJECTION);
gGL.pushMatrix();
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
gGL.pushMatrix();
glLoadIdentity();
gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
gl_rect_2d_simple( width, height );
bool avatar_preview = false;
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{
LLModelInstance& instance = *model_iter;
LLModel* model = instance.mModel;
if (!model->mSkinWeights.empty())
{
avatar_preview = true;
}
}
}
mFMP->childSetEnabled("consolidate", !avatar_preview);
F32 explode = mFMP->childGetValue("explode").asReal();
glMatrixMode(GL_PROJECTION);
gGL.popMatrix();
glMatrixMode(GL_MODELVIEW);
gGL.popMatrix();
glClear(GL_DEPTH_BUFFER_BIT);
LLViewerCamera::getInstance()->setAspect((F32) width / height );
LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
LLVector3 target_pos = mPreviewTarget;
LLVector3 offset = mCameraOffset;
F32 z_near = llmax(mCameraDistance-mPreviewScale.magVec(), 0.001f);
F32 z_far = mCameraDistance+mPreviewScale.magVec();
if (avatar_preview)
{
target_pos = gAgentAvatarp->getPositionAgent();
z_near = 0.01f;
z_far = 1024.f;
mCameraDistance = 16.f;
//render avatar previews every frame
refresh();
}
LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
LLQuaternion(mCameraYaw, LLVector3::z_axis);
LLQuaternion av_rot = camera_rot;
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, width, height, FALSE, z_near, z_far);
stop_glerror();
gPipeline.enableLightsAvatar();
gGL.pushMatrix();
const F32 BRIGHTNESS = 0.9f;
gGL.color3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
LLGLEnable normalize(GL_NORMALIZE);
if (!mBaseModel.empty() && mVertexBuffer[5].empty())
{
genBuffers(-1);
genBuffers(3);
//genLODs();
}
bool physics = (mPreviewLOD == LLModel::LOD_PHYSICS);
S32 physics_idx = -1;
bool render_mesh = true;
bool render_hull = false;
if (physics && mFMP->mDecompFloater)
{
physics_idx = mFMP->mDecompFloater->childGetValue("model").asInteger();
render_mesh = mFMP->mDecompFloater->childGetValue("render_mesh").asBoolean();
render_hull = mFMP->mDecompFloater->childGetValue("render_hull").asBoolean();
}
if (!mModel[mPreviewLOD].empty())
{
if (mVertexBuffer[mPreviewLOD].empty())
{
genBuffers(mPreviewLOD);
}
if (!avatar_preview)
{
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{
gGL.pushMatrix();
LLMatrix4 mat = iter->first;
glMultMatrixf((GLfloat*) mat.mMatrix);
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{
LLModelInstance& instance = *model_iter;
LLModel* model = instance.mModel;
if (instance.mTransform != mat)
{
llerrs << "WTF?" << llendl;
}
if (render_mesh)
{
for (U32 i = 0; i < mVertexBuffer[mPreviewLOD][model].size(); ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
if (physics)
{
if (physics_idx > -1 && model == mModel[mPreviewLOD][physics_idx])
{
glColor4f(1,0,0,1);
}
else
{
glColor4f(0.75f, 0.75f, 0.75f, 1.f);
}
}
else
{
glColor4fv(instance.mMaterial[i].mDiffuseColor.mV);
if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull())
{
gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true);
if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1)
{
mTextureSet.insert(instance.mMaterial[i].mDiffuseMap);
}
}
}
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
glColor3f(0.4f, 0.4f, 0.4f);
if (mFMP->childGetValue("show edges").asBoolean())
{
glLineWidth(3.f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(1.f);
}
}
}
if (render_hull)
{
LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread;
if (decomp)
{
LLMutexLock(decomp->mMutex);
std::map<LLModel*, std::vector<LLPointer<LLVertexBuffer> > >::iterator iter =
mPhysicsMesh.find(model);
if (iter != mPhysicsMesh.end())
{
for (U32 i = 0; i < iter->second.size(); ++i)
{
if (explode > 0.f)
{
gGL.pushMatrix();
LLVector3 offset = model->mHullCenter[i]-model->mPhysicsCenter;
offset *= explode;
gGL.translatef(offset.mV[0], offset.mV[1], offset.mV[2]);
}
static std::vector<LLColor4U> hull_colors;
if (i+1 >= hull_colors.size())
{
hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 255));
}
LLVertexBuffer* buff = iter->second[i];
if (buff)
{
buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL);
glColor4ubv(hull_colors[i].mV);
buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts());
if (mFMP->childGetValue("show edges").asBoolean())
{
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glLineWidth(3.f);
glColor4ub(hull_colors[i].mV[0]/2, hull_colors[i].mV[1]/2, hull_colors[i].mV[2]/2, 255);
buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts());
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(1.f);
}
}
if (explode > 0.f)
{
gGL.popMatrix();
}
}
}
}
//mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[HULLS]", llformat("%d",decomp->mHulls.size()));
//mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[POINTS]", llformat("%d",decomp->mTotalPoints));
}
}
gGL.popMatrix();
}
if (physics)
{
mPreviewLOD = LLModel::LOD_PHYSICS;
}
}
else
{
LLVOAvatarSelf* avatar = gAgentAvatarp;
target_pos = avatar->getPositionAgent();
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
avatar->renderCollisionVolumes();
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{
LLModelInstance& instance = *model_iter;
LLModel* model = instance.mModel;
if (!model->mSkinWeights.empty())
{
for (U32 i = 0; i < mVertexBuffer[mPreviewLOD][model].size(); ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
const LLVolumeFace& face = model->getVolumeFace(i);
LLStrider<LLVector3> position;
buffer->getVertexStrider(position);
LLStrider<LLVector4> weight;
buffer->getWeight4Strider(weight);
//quick 'n dirty software vertex skinning
//build matrix palette
LLMatrix4 mat[64];
for (U32 j = 0; j < model->mJointList.size(); ++j)
{
LLJoint* joint = avatar->getJoint(model->mJointList[j]);
if (joint)
{
mat[j] = model->mInvBindMatrix[j];
mat[j] *= joint->getWorldMatrix();
}
}
for (U32 j = 0; j < buffer->getRequestedVerts(); ++j)
{
LLMatrix4 final_mat;
final_mat.mMatrix[0][0] = final_mat.mMatrix[1][1] = final_mat.mMatrix[2][2] = final_mat.mMatrix[3][3] = 0.f;
LLVector4 wght;
S32 idx[4];
F32 scale = 0.f;
for (U32 k = 0; k < 4; k++)
{
F32 w = weight[j].mV[k];
idx[k] = (S32) floorf(w);
wght.mV[k] = w - floorf(w);
scale += wght.mV[k];
}
wght *= 1.f/scale;
for (U32 k = 0; k < 4; k++)
{
F32* src = (F32*) mat[idx[k]].mMatrix;
F32* dst = (F32*) final_mat.mMatrix;
F32 w = wght.mV[k];
for (U32 l = 0; l < 16; l++)
{
dst[l] += src[l]*w;
}
}
//VECTORIZE THIS
LLVector3 v(face.mPositions[j].getF32ptr());
v = v * model->mBindShapeMatrix;
v = v * final_mat;
position[j] = v;
}
buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
glColor4fv(instance.mMaterial[i].mDiffuseColor.mV);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
glColor3f(0.4f, 0.4f, 0.4f);
if (mFMP->childGetValue("show edges").asBoolean())
{
glLineWidth(3.f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(1.f);
}
}
}
}
}
}
}
gGL.popMatrix();
return TRUE;
}
//-----------------------------------------------------------------------------
// refresh()
//-----------------------------------------------------------------------------
void LLModelPreview::refresh()
{
mNeedsUpdate = TRUE;
}
//-----------------------------------------------------------------------------
// rotate()
//-----------------------------------------------------------------------------
void LLModelPreview::rotate(F32 yaw_radians, F32 pitch_radians)
{
mCameraYaw = mCameraYaw + yaw_radians;
mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
}
//-----------------------------------------------------------------------------
// zoom()
//-----------------------------------------------------------------------------
void LLModelPreview::zoom(F32 zoom_amt)
{
F32 new_zoom = mCameraZoom+zoom_amt;
mCameraZoom = llclamp(new_zoom, 1.f, 10.f);
}
void LLModelPreview::pan(F32 right, F32 up)
{
mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom, -1.f, 1.f);
mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom, -1.f, 1.f);
}
void LLModelPreview::setPreviewLOD(S32 lod)
{
mPreviewLOD = llclamp(lod, 0, 4);
refresh();
}
//static
void LLFloaterModelPreview::onBrowseHighLOD(void* data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data;
mp->loadModel(3);
}
//static
void LLFloaterModelPreview::onBrowseMediumLOD(void* data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data;
mp->loadModel(2);
}
//static
void LLFloaterModelPreview::onBrowseLowLOD(void* data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data;
mp->loadModel(1);
}
//static
void LLFloaterModelPreview::onBrowseLowestLOD(void* data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data;
mp->loadModel(0);
}
//static
void LLFloaterModelPreview::onUpload(void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
if (mp->mDecompFloater)
{
mp->mDecompFloater->closeFloater();
}
mp->mModelPreview->rebuildUploadData();
gMeshRepo.uploadModel(mp->mModelPreview->mUploadData, mp->mModelPreview->mPreviewScale, mp->childGetValue("upload_textures").asBoolean());
mp->closeFloater(false);
}
//static
void LLFloaterModelPreview::onConsolidate(void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->mModelPreview->consolidate();
}
//static
void LLFloaterModelPreview::onScrubMaterials(void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->mModelPreview->scrubMaterials();
}
//static
void LLFloaterModelPreview::onDecompose(void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->showDecompFloater();
}
//static
void LLFloaterModelPreview::onModelDecompositionComplete(LLModel* model, std::vector<LLPointer<LLVertexBuffer> >& physics_mesh)
{
if (sInstance && sInstance->mModelPreview)
{
sInstance->mModelPreview->mPhysicsMesh[model] = physics_mesh;
sInstance->mModelPreview->mResourceCost = sInstance->mModelPreview->calcResourceCost();
}
}
//static
void LLFloaterModelPreview::refresh(LLUICtrl* ctrl, void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->mModelPreview->refresh();
}
void LLFloaterModelPreview::updateResourceCost()
{
U32 cost = mModelPreview->mResourceCost;
childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",cost));
}
//static
void LLModelPreview::textureLoadedCallback( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata )
{
LLModelPreview* preview = (LLModelPreview*) userdata;
preview->refresh();
}
#endif
|