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
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "IrrCompileConfig.h"
#include "CSceneManager.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"
#include "SAnimatedMesh.h"
#include "CMeshCache.h"
#include "IXMLWriter.h"
#include "ISceneUserDataSerializer.h"
#include "IGUIEnvironment.h"
#include "IMaterialRenderer.h"
#include "IReadFile.h"
#include "IWriteFile.h"
#include "ISceneLoader.h"
#include "os.h"
// We need this include for the case of skinned mesh support without
// any such loader
#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
#include "CSkinnedMesh.h"
#endif
#ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
#include "CIrrMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_BSP_LOADER_
#include "CBSPMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_MD2_LOADER_
#include "CMD2MeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_HALFLIFE_LOADER_
#include "CAnimatedMeshHalfLife.h"
#endif
#ifdef _IRR_COMPILE_WITH_MS3D_LOADER_
#include "CMS3DMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_3DS_LOADER_
#include "C3DSMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_X_LOADER_
#include "CXMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_OCT_LOADER_
#include "COCTLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_CSM_LOADER_
#include "CCSMLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_LMTS_LOADER_
#include "CLMTSMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_MY3D_LOADER_
#include "CMY3DMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_COLLADA_LOADER_
#include "CColladaFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_
#include "CDMFLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_OGRE_LOADER_
#include "COgreMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_OBJ_LOADER_
#include "COBJMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_MD3_LOADER_
#include "CMD3MeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_B3D_LOADER_
#include "CB3DMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_LWO_LOADER_
#include "CLWOMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_STL_LOADER_
#include "CSTLMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_PLY_LOADER_
#include "CPLYMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_SMF_LOADER_
#include "CSMFMeshFileLoader.h"
#endif
#ifdef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_
#include "CSceneLoaderIrr.h"
#endif
#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_
#include "CColladaMeshWriter.h"
#endif
#ifdef _IRR_COMPILE_WITH_IRR_WRITER_
#include "CIrrMeshWriter.h"
#endif
#ifdef _IRR_COMPILE_WITH_STL_WRITER_
#include "CSTLMeshWriter.h"
#endif
#ifdef _IRR_COMPILE_WITH_OBJ_WRITER_
#include "COBJMeshWriter.h"
#endif
#ifdef _IRR_COMPILE_WITH_PLY_WRITER_
#include "CPLYMeshWriter.h"
#endif
#include "CCubeSceneNode.h"
#include "CSphereSceneNode.h"
#include "CAnimatedMeshSceneNode.h"
#include "COctreeSceneNode.h"
#include "CCameraSceneNode.h"
#include "CLightSceneNode.h"
#include "CBillboardSceneNode.h"
#include "CMeshSceneNode.h"
#include "CSkyBoxSceneNode.h"
#include "CSkyDomeSceneNode.h"
#include "CParticleSystemSceneNode.h"
#include "CDummyTransformationSceneNode.h"
#include "CWaterSurfaceSceneNode.h"
#include "CTerrainSceneNode.h"
#include "CEmptySceneNode.h"
#include "CTextSceneNode.h"
#include "CQuake3ShaderSceneNode.h"
#include "CVolumeLightSceneNode.h"
#include "CDefaultSceneNodeFactory.h"
#include "CSceneCollisionManager.h"
#include "CTriangleSelector.h"
#include "COctreeTriangleSelector.h"
#include "CTriangleBBSelector.h"
#include "CMetaTriangleSelector.h"
#include "CTerrainTriangleSelector.h"
#include "CSceneNodeAnimatorRotation.h"
#include "CSceneNodeAnimatorFlyCircle.h"
#include "CSceneNodeAnimatorFlyStraight.h"
#include "CSceneNodeAnimatorTexture.h"
#include "CSceneNodeAnimatorCollisionResponse.h"
#include "CSceneNodeAnimatorDelete.h"
#include "CSceneNodeAnimatorFollowSpline.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "CDefaultSceneNodeAnimatorFactory.h"
#include "CGeometryCreator.h"
namespace irr
{
namespace scene
{
//! constructor
CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
gui::ICursorControl* cursorControl, IMeshCache* cache,
gui::IGUIEnvironment* gui)
: ISceneNode(0, 0), Driver(driver), FileSystem(fs), GUIEnvironment(gui),
CursorControl(cursorControl), CollisionManager(0),
ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0),
MeshCache(cache), CurrentRendertime(ESNRP_NONE), LightManager(0),
IRR_XML_FORMAT_SCENE(L"irr_scene"), IRR_XML_FORMAT_NODE(L"node"), IRR_XML_FORMAT_NODE_ATTR_TYPE(L"type")
{
#ifdef _DEBUG
ISceneManager::setDebugName("CSceneManager ISceneManager");
ISceneNode::setDebugName("CSceneManager ISceneNode");
#endif
// root node's scene manager
SceneManager = this;
// set scene parameters
Parameters.setAttribute( DEBUG_NORMAL_LENGTH, 1.f );
Parameters.setAttribute( DEBUG_NORMAL_COLOR, video::SColor(255, 34, 221, 221));
if (Driver)
Driver->grab();
if (FileSystem)
FileSystem->grab();
if (CursorControl)
CursorControl->grab();
if (GUIEnvironment)
GUIEnvironment->grab();
// create mesh cache if not there already
if (!MeshCache)
MeshCache = new CMeshCache();
else
MeshCache->grab();
// create collision manager
CollisionManager = new CSceneCollisionManager(this, Driver);
// create geometry creator
GeometryCreator = new CGeometryCreator();
// add file format loaders. add the least commonly used ones first,
// as these are checked last
// TODO: now that we have multiple scene managers, these should be
// shallow copies from the previous manager if there is one.
#ifdef _IRR_COMPILE_WITH_STL_LOADER_
MeshLoaderList.push_back(new CSTLMeshFileLoader());
#endif
#ifdef _IRR_COMPILE_WITH_PLY_LOADER_
MeshLoaderList.push_back(new CPLYMeshFileLoader(this));
#endif
#ifdef _IRR_COMPILE_WITH_SMF_LOADER_
MeshLoaderList.push_back(new CSMFMeshFileLoader(Driver));
#endif
#ifdef _IRR_COMPILE_WITH_OCT_LOADER_
MeshLoaderList.push_back(new COCTLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_CSM_LOADER_
MeshLoaderList.push_back(new CCSMLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_LMTS_LOADER_
MeshLoaderList.push_back(new CLMTSMeshFileLoader(FileSystem, Driver, &Parameters));
#endif
#ifdef _IRR_COMPILE_WITH_MY3D_LOADER_
MeshLoaderList.push_back(new CMY3DMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_
MeshLoaderList.push_back(new CDMFLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_OGRE_LOADER_
MeshLoaderList.push_back(new COgreMeshFileLoader(FileSystem, Driver));
#endif
#ifdef _IRR_COMPILE_WITH_HALFLIFE_LOADER_
MeshLoaderList.push_back(new CHalflifeMDLMeshFileLoader( this ));
#endif
#ifdef _IRR_COMPILE_WITH_MD3_LOADER_
MeshLoaderList.push_back(new CMD3MeshFileLoader( this));
#endif
#ifdef _IRR_COMPILE_WITH_LWO_LOADER_
MeshLoaderList.push_back(new CLWOMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_MD2_LOADER_
MeshLoaderList.push_back(new CMD2MeshFileLoader());
#endif
#ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_
MeshLoaderList.push_back(new CIrrMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_BSP_LOADER_
MeshLoaderList.push_back(new CBSPMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_COLLADA_LOADER_
MeshLoaderList.push_back(new CColladaFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_3DS_LOADER_
MeshLoaderList.push_back(new C3DSMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_X_LOADER_
MeshLoaderList.push_back(new CXMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_MS3D_LOADER_
MeshLoaderList.push_back(new CMS3DMeshFileLoader(Driver));
#endif
#ifdef _IRR_COMPILE_WITH_OBJ_LOADER_
MeshLoaderList.push_back(new COBJMeshFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_B3D_LOADER_
MeshLoaderList.push_back(new CB3DMeshFileLoader(this));
#endif
// scene loaders
#ifdef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_
SceneLoaderList.push_back(new CSceneLoaderIrr(this, FileSystem));
#endif
// factories
ISceneNodeFactory* factory = new CDefaultSceneNodeFactory(this);
registerSceneNodeFactory(factory);
factory->drop();
ISceneNodeAnimatorFactory* animatorFactory = new CDefaultSceneNodeAnimatorFactory(this, CursorControl);
registerSceneNodeAnimatorFactory(animatorFactory);
animatorFactory->drop();
}
//! destructor
CSceneManager::~CSceneManager()
{
clearDeletionList();
//! force to remove hardwareTextures from the driver
//! because Scenes may hold internally data bounded to sceneNodes
//! which may be destroyed twice
if (Driver)
Driver->removeAllHardwareBuffers();
if (FileSystem)
FileSystem->drop();
if (CursorControl)
CursorControl->drop();
if (CollisionManager)
CollisionManager->drop();
if (GeometryCreator)
GeometryCreator->drop();
if (GUIEnvironment)
GUIEnvironment->drop();
u32 i;
for (i=0; i<MeshLoaderList.size(); ++i)
MeshLoaderList[i]->drop();
for (i=0; i<SceneLoaderList.size(); ++i)
SceneLoaderList[i]->drop();
if (ActiveCamera)
ActiveCamera->drop();
ActiveCamera = 0;
if (MeshCache)
MeshCache->drop();
for (i=0; i<SceneNodeFactoryList.size(); ++i)
SceneNodeFactoryList[i]->drop();
for (i=0; i<SceneNodeAnimatorFactoryList.size(); ++i)
SceneNodeAnimatorFactoryList[i]->drop();
if (LightManager)
LightManager->drop();
// remove all nodes and animators before dropping the driver
// as render targets may be destroyed twice
removeAll();
removeAnimators();
if (Driver)
Driver->drop();
}
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* CSceneManager::getMesh(const io::path& filename)
{
IAnimatedMesh* msh = MeshCache->getMeshByName(filename);
if (msh)
return msh;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (!file)
{
os::Printer::log("Could not load mesh, because file could not be opened: ", filename, ELL_ERROR);
return 0;
}
// iterate the list in reverse order so user-added loaders can override the built-in ones
s32 count = MeshLoaderList.size();
for (s32 i=count-1; i>=0; --i)
{
if (MeshLoaderList[i]->isALoadableFileExtension(filename))
{
// reset file to avoid side effects of previous calls to createMesh
file->seek(0);
msh = MeshLoaderList[i]->createMesh(file);
if (msh)
{
MeshCache->addMesh(filename, msh);
msh->drop();
break;
}
}
}
file->drop();
if (!msh)
os::Printer::log("Could not load mesh, file format seems to be unsupported", filename, ELL_ERROR);
else
os::Printer::log("Loaded mesh", filename, ELL_INFORMATION);
return msh;
}
//! gets an animateable mesh. loads it if needed. returned pointer must not be dropped.
IAnimatedMesh* CSceneManager::getMesh(io::IReadFile* file)
{
if (!file)
return 0;
io::path name = file->getFileName();
IAnimatedMesh* msh = MeshCache->getMeshByName(file->getFileName());
if (msh)
return msh;
// iterate the list in reverse order so user-added loaders can override the built-in ones
s32 count = MeshLoaderList.size();
for (s32 i=count-1; i>=0; --i)
{
if (MeshLoaderList[i]->isALoadableFileExtension(name))
{
// reset file to avoid side effects of previous calls to createMesh
file->seek(0);
msh = MeshLoaderList[i]->createMesh(file);
if (msh)
{
MeshCache->addMesh(file->getFileName(), msh);
msh->drop();
break;
}
}
}
if (!msh)
os::Printer::log("Could not load mesh, file format seems to be unsupported", file->getFileName(), ELL_ERROR);
else
os::Printer::log("Loaded mesh", file->getFileName(), ELL_INFORMATION);
return msh;
}
//! returns the video driver
video::IVideoDriver* CSceneManager::getVideoDriver()
{
return Driver;
}
//! returns the GUI Environment
gui::IGUIEnvironment* CSceneManager::getGUIEnvironment()
{
return GUIEnvironment;
}
//! Get the active FileSystem
/** \return Pointer to the FileSystem
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
io::IFileSystem* CSceneManager::getFileSystem()
{
return FileSystem;
}
//! Adds a text scene node, which is able to display
//! 2d text at a position in three dimensional space
ITextSceneNode* CSceneManager::addTextSceneNode(gui::IGUIFont* font,
const wchar_t* text, video::SColor color, ISceneNode* parent,
const core::vector3df& position, s32 id)
{
if (!font)
return 0;
if (!parent)
parent = this;
ITextSceneNode* t = new CTextSceneNode(parent, this, id, font,
getSceneCollisionManager(), position, text, color);
t->drop();
return t;
}
//! Adds a text scene node, which uses billboards
IBillboardTextSceneNode* CSceneManager::addBillboardTextSceneNode(gui::IGUIFont* font,
const wchar_t* text, ISceneNode* parent,
const core::dimension2d<f32>& size,
const core::vector3df& position, s32 id,
video::SColor colorTop, video::SColor colorBottom)
{
if (!font && GUIEnvironment)
font = GUIEnvironment->getBuiltInFont();
if (!font)
return 0;
if (!parent)
parent = this;
IBillboardTextSceneNode* node = new CBillboardTextSceneNode(parent, this, id, font, text, position, size,
colorTop, colorBottom);
node->drop();
return node;
}
//! Adds a scene node, which can render a quake3 shader
IMeshSceneNode* CSceneManager::addQuake3SceneNode(const IMeshBuffer* meshBuffer,
const quake3::IShader * shader,
ISceneNode* parent, s32 id )
{
#ifdef _IRR_COMPILE_WITH_BSP_LOADER_
if (!shader)
return 0;
if (!parent)
parent = this;
CQuake3ShaderSceneNode* node = new CQuake3ShaderSceneNode( parent,
this, id, FileSystem,
meshBuffer, shader );
node->drop();
return node;
#else
return 0;
#endif
}
//! adds Volume Lighting Scene Node.
//! the returned pointer must not be dropped.
IVolumeLightSceneNode* CSceneManager::addVolumeLightSceneNode(
ISceneNode* parent, s32 id,
const u32 subdivU, const u32 subdivV,
const video::SColor foot, const video::SColor tail,
const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& scale)
{
if (!parent)
parent = this;
IVolumeLightSceneNode* node = new CVolumeLightSceneNode(parent, this, id, subdivU, subdivV, foot, tail, position, rotation, scale);
node->drop();
return node;
}
//! adds a test scene node for test purposes to the scene. It is a simple cube of (1,1,1) size.
//! the returned pointer must not be dropped.
IMeshSceneNode* CSceneManager::addCubeSceneNode(f32 size, ISceneNode* parent,
s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
{
if (!parent)
parent = this;
IMeshSceneNode* node = new CCubeSceneNode(size, parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! Adds a sphere scene node for test purposes to the scene.
IMeshSceneNode* CSceneManager::addSphereSceneNode(f32 radius, s32 polyCount,
ISceneNode* parent, s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
{
if (!parent)
parent = this;
IMeshSceneNode* node = new CSphereSceneNode(radius, polyCount, polyCount, parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! adds a scene node for rendering a static mesh
//! the returned pointer must not be dropped.
IMeshSceneNode* CSceneManager::addMeshSceneNode(IMesh* mesh, ISceneNode* parent, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale, bool alsoAddIfMeshPointerZero)
{
if (!alsoAddIfMeshPointerZero && !mesh)
return 0;
if (!parent)
parent = this;
IMeshSceneNode* node = new CMeshSceneNode(mesh, parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! Adds a scene node for rendering a animated water surface mesh.
ISceneNode* CSceneManager::addWaterSurfaceSceneNode(IMesh* mesh, f32 waveHeight, f32 waveSpeed, f32 waveLength,
ISceneNode* parent, s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
{
if (!parent)
parent = this;
ISceneNode* node = new CWaterSurfaceSceneNode(waveHeight, waveSpeed, waveLength,
mesh, parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! adds a scene node for rendering an animated mesh model
IAnimatedMeshSceneNode* CSceneManager::addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale, bool alsoAddIfMeshPointerZero)
{
if (!alsoAddIfMeshPointerZero && !mesh)
return 0;
if (!parent)
parent = this;
IAnimatedMeshSceneNode* node =
new CAnimatedMeshSceneNode(mesh, parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! Adds a scene node for rendering using a octree to the scene graph. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree.
IMeshSceneNode* CSceneManager::addOctreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent,
s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero)
{
if (!alsoAddIfMeshPointerZero && (!mesh || !mesh->getFrameCount()))
return 0;
return addOctreeSceneNode(mesh ? mesh->getMesh(0) : 0,
parent, id, minimalPolysPerNode,
alsoAddIfMeshPointerZero);
}
//! Adds a scene node for rendering using a octree. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree.
IMeshSceneNode* CSceneManager::addOctreeSceneNode(IMesh* mesh, ISceneNode* parent,
s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero)
{
if (!alsoAddIfMeshPointerZero && !mesh)
return 0;
if (!parent)
parent = this;
COctreeSceneNode* node = new COctreeSceneNode(parent, this, id, minimalPolysPerNode);
if (node)
{
node->setMesh(mesh);
node->drop();
}
return node;
}
//! Adds a camera scene node to the tree and sets it as active camera.
//! \param position: Position of the space relative to its parent where the camera will be placed.
//! \param lookat: Position where the camera will look at. Also known as target.
//! \param parent: Parent scene node of the camera. Can be null. If the parent moves,
//! the camera will move too.
//! \return Returns pointer to interface to camera
ICameraSceneNode* CSceneManager::addCameraSceneNode(ISceneNode* parent,
const core::vector3df& position, const core::vector3df& lookat, s32 id,
bool makeActive)
{
if (!parent)
parent = this;
ICameraSceneNode* node = new CCameraSceneNode(parent, this, id, position, lookat);
if (makeActive)
setActiveCamera(node);
node->drop();
return node;
}
//! Adds a camera scene node which is able to be controlled with the mouse similar
//! to in the 3D Software Maya by Alias Wavefront.
//! The returned pointer must not be dropped.
ICameraSceneNode* CSceneManager::addCameraSceneNodeMaya(ISceneNode* parent,
f32 rotateSpeed, f32 zoomSpeed, f32 translationSpeed, s32 id, f32 distance,
bool makeActive)
{
ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
core::vector3df(0,0,100), id, makeActive);
if (node)
{
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraMaya(CursorControl,
rotateSpeed, zoomSpeed, translationSpeed, distance);
node->addAnimator(anm);
anm->drop();
}
return node;
}
//! Adds a camera scene node which is able to be controlled with the mouse and keys
//! like in most first person shooters (FPS):
ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(ISceneNode* parent,
f32 rotateSpeed, f32 moveSpeed, s32 id, SKeyMap* keyMapArray,
s32 keyMapSize, bool noVerticalMovement, f32 jumpSpeed,
bool invertMouseY, bool makeActive)
{
ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
core::vector3df(0,0,100), id, makeActive);
if (node)
{
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraFPS(CursorControl,
rotateSpeed, moveSpeed, jumpSpeed,
keyMapArray, keyMapSize, noVerticalMovement, invertMouseY);
// Bind the node's rotation to its target. This is consistent with 1.4.2 and below.
node->bindTargetAndRotation(true);
node->addAnimator(anm);
anm->drop();
}
return node;
}
//! Adds a dynamic light scene node. The light will cast dynamic light on all
//! other scene nodes in the scene, which have the material flag video::MTF_LIGHTING
//! turned on. (This is the default setting in most scene nodes).
ILightSceneNode* CSceneManager::addLightSceneNode(ISceneNode* parent,
const core::vector3df& position, video::SColorf color, f32 range, s32 id)
{
if (!parent)
parent = this;
ILightSceneNode* node = new CLightSceneNode(parent, this, id, position, color, range);
node->drop();
return node;
}
//! Adds a billboard scene node to the scene. A billboard is like a 3d sprite: A 2d element,
//! which always looks to the camera. It is usually used for things like explosions, fire,
//! lensflares and things like that.
IBillboardSceneNode* CSceneManager::addBillboardSceneNode(ISceneNode* parent,
const core::dimension2d<f32>& size, const core::vector3df& position, s32 id,
video::SColor colorTop, video::SColor colorBottom
)
{
if (!parent)
parent = this;
IBillboardSceneNode* node = new CBillboardSceneNode(parent, this, id, position, size,
colorTop, colorBottom);
node->drop();
return node;
}
//! Adds a skybox scene node. A skybox is a big cube with 6 textures on it and
//! is drawn around the camera position.
ISceneNode* CSceneManager::addSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom,
video::ITexture* left, video::ITexture* right, video::ITexture* front,
video::ITexture* back, ISceneNode* parent, s32 id)
{
if (!parent)
parent = this;
ISceneNode* node = new CSkyBoxSceneNode(top, bottom, left, right,
front, back, parent, this, id);
node->drop();
return node;
}
//! Adds a skydome scene node. A skydome is a large (half-) sphere with a
//! panoramic texture on it and is drawn around the camera position.
ISceneNode* CSceneManager::addSkyDomeSceneNode(video::ITexture* texture,
u32 horiRes, u32 vertRes, f32 texturePercentage,f32 spherePercentage, f32 radius,
ISceneNode* parent, s32 id)
{
if (!parent)
parent = this;
ISceneNode* node = new CSkyDomeSceneNode(texture, horiRes, vertRes,
texturePercentage, spherePercentage, radius, parent, this, id);
node->drop();
return node;
}
//! Adds a particle system scene node.
IParticleSystemSceneNode* CSceneManager::addParticleSystemSceneNode(
bool withDefaultEmitter, ISceneNode* parent, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale)
{
if (!parent)
parent = this;
IParticleSystemSceneNode* node = new CParticleSystemSceneNode(withDefaultEmitter,
parent, this, id, position, rotation, scale);
node->drop();
return node;
}
//! Adds a terrain scene node to the scene graph.
ITerrainSceneNode* CSceneManager::addTerrainSceneNode(
const io::path& heightMapFileName,
ISceneNode* parent, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale,
video::SColor vertexColor,
s32 maxLOD, E_TERRAIN_PATCH_SIZE patchSize, s32 smoothFactor,
bool addAlsoIfHeightmapEmpty)
{
io::IReadFile* file = FileSystem->createAndOpenFile(heightMapFileName);
if (!file && !addAlsoIfHeightmapEmpty)
{
os::Printer::log("Could not load terrain, because file could not be opened.",
heightMapFileName, ELL_ERROR);
return 0;
}
ITerrainSceneNode* terrain = addTerrainSceneNode(file, parent, id,
position, rotation, scale, vertexColor, maxLOD, patchSize,
smoothFactor, addAlsoIfHeightmapEmpty);
if (file)
file->drop();
return terrain;
}
//! Adds a terrain scene node to the scene graph.
ITerrainSceneNode* CSceneManager::addTerrainSceneNode(
io::IReadFile* heightMapFile,
ISceneNode* parent, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale,
video::SColor vertexColor,
s32 maxLOD, E_TERRAIN_PATCH_SIZE patchSize,
s32 smoothFactor,
bool addAlsoIfHeightmapEmpty)
{
if (!parent)
parent = this;
if (!heightMapFile && !addAlsoIfHeightmapEmpty)
{
os::Printer::log("Could not load terrain, because file could not be opened.", ELL_ERROR);
return 0;
}
CTerrainSceneNode* node = new CTerrainSceneNode(parent, this, FileSystem, id,
maxLOD, patchSize, position, rotation, scale);
if (!node->loadHeightMap(heightMapFile, vertexColor, smoothFactor))
{
if (!addAlsoIfHeightmapEmpty)
{
node->remove();
node->drop();
return 0;
}
}
node->drop();
return node;
}
//! Adds an empty scene node.
ISceneNode* CSceneManager::addEmptySceneNode(ISceneNode* parent, s32 id)
{
if (!parent)
parent = this;
ISceneNode* node = new CEmptySceneNode(parent, this, id);
node->drop();
return node;
}
//! Adds a dummy transformation scene node to the scene graph.
IDummyTransformationSceneNode* CSceneManager::addDummyTransformationSceneNode(
ISceneNode* parent, s32 id)
{
if (!parent)
parent = this;
IDummyTransformationSceneNode* node = new CDummyTransformationSceneNode(
parent, this, id);
node->drop();
return node;
}
//! Adds a Hill Plane mesh to the mesh pool. The mesh is generated on the fly
//! and looks like a plane with some hills on it. You can specify how many hills
//! there should be on the plane and how high they should be. Also you must
//! specify a name for the mesh, because the mesh is added to the mesh pool,
//! and can be retrieved again using ISceneManager::getMesh with the name as
//! parameter.
IAnimatedMesh* CSceneManager::addHillPlaneMesh(const io::path& name,
const core::dimension2d<f32>& tileSize,
const core::dimension2d<u32>& tileCount,
video::SMaterial* material, f32 hillHeight,
const core::dimension2d<f32>& countHills,
const core::dimension2d<f32>& textureRepeatCount)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createHillPlaneMesh(tileSize,
tileCount, material, hillHeight, countHills,
textureRepeatCount);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
//! Adds a terrain mesh to the mesh pool.
IAnimatedMesh* CSceneManager::addTerrainMesh(const io::path& name,
video::IImage* texture, video::IImage* heightmap,
const core::dimension2d<f32>& stretchSize,
f32 maxHeight,
const core::dimension2d<u32>& defaultVertexBlockSize)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByName(name);
const bool debugBorders=false;
IMesh* mesh = GeometryCreator->createTerrainMesh(texture, heightmap,
stretchSize, maxHeight, Driver,
defaultVertexBlockSize, debugBorders);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
//! Adds an arrow mesh to the mesh pool.
IAnimatedMesh* CSceneManager::addArrowMesh(const io::path& name,
video::SColor vtxColor0, video::SColor vtxColor1,
u32 tesselationCylinder, u32 tesselationCone, f32 height,
f32 cylinderHeight, f32 width0,f32 width1)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createArrowMesh( tesselationCylinder,
tesselationCone, height, cylinderHeight, width0,width1,
vtxColor0, vtxColor1);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
//! Adds a static sphere mesh to the mesh pool.
IAnimatedMesh* CSceneManager::addSphereMesh(const io::path& name,
f32 radius, u32 polyCountX, u32 polyCountY)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createSphereMesh(radius, polyCountX, polyCountY);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
//! Adds a static volume light mesh to the mesh pool.
IAnimatedMesh* CSceneManager::addVolumeLightMesh(const io::path& name,
const u32 SubdivideU, const u32 SubdivideV,
const video::SColor FootColor, const video::SColor TailColor)
{
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByName(name);
IMesh* mesh = GeometryCreator->createVolumeLightMesh(SubdivideU, SubdivideV, FootColor, TailColor);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
//! Returns the root scene node. This is the scene node wich is parent
//! of all scene nodes. The root scene node is a special scene node which
//! only exists to manage all scene nodes. It is not rendered and cannot
//! be removed from the scene.
//! \return Returns a pointer to the root scene node.
ISceneNode* CSceneManager::getRootSceneNode()
{
return this;
}
//! Returns the current active camera.
//! \return The active camera is returned. Note that this can be NULL, if there
//! was no camera created yet.
ICameraSceneNode* CSceneManager::getActiveCamera() const
{
return ActiveCamera;
}
//! Sets the active camera. The previous active camera will be deactivated.
//! \param camera: The new camera which should be active.
void CSceneManager::setActiveCamera(ICameraSceneNode* camera)
{
if (camera)
camera->grab();
if (ActiveCamera)
ActiveCamera->drop();
ActiveCamera = camera;
}
//! renders the node.
void CSceneManager::render()
{
}
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32>& CSceneManager::getBoundingBox() const
{
_IRR_DEBUG_BREAK_IF(true) // Bounding Box of Scene Manager wanted.
// should never be used.
return *((core::aabbox3d<f32>*)0);
}
//! returns if node is culled
bool CSceneManager::isCulled(const ISceneNode* node) const
{
const ICameraSceneNode* cam = getActiveCamera();
if (!cam)
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false;
}
bool result = false;
// has occlusion query information
if (node->getAutomaticCulling() & scene::EAC_OCC_QUERY)
{
result = (Driver->getOcclusionQueryResult(const_cast<ISceneNode*>(node))==0);
}
// can be seen by a bounding box ?
if (!result && (node->getAutomaticCulling() & scene::EAC_BOX))
{
core::aabbox3d<f32> tbox = node->getBoundingBox();
node->getAbsoluteTransformation().transformBoxEx(tbox);
result = !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox() ));
}
// can be seen by a bounding sphere
if (!result && (node->getAutomaticCulling() & scene::EAC_FRUSTUM_SPHERE))
{ // requires bbox diameter
}
// can be seen by cam pyramid planes ?
if (!result && (node->getAutomaticCulling() & scene::EAC_FRUSTUM_BOX))
{
SViewFrustum frust = *cam->getViewFrustum();
//transform the frustum to the node's current absolute transformation
core::matrix4 invTrans(node->getAbsoluteTransformation(), core::matrix4::EM4CONST_INVERSE);
//invTrans.makeInverse();
frust.transform(invTrans);
core::vector3df edges[8];
node->getBoundingBox().getEdges(edges);
for (s32 i=0; i<scene::SViewFrustum::VF_PLANE_COUNT; ++i)
{
bool boxInFrustum=false;
for (u32 j=0; j<8; ++j)
{
if (frust.planes[i].classifyPointRelation(edges[j]) != core::ISREL3D_FRONT)
{
boxInFrustum=true;
break;
}
}
if (!boxInFrustum)
{
result = true;
break;
}
}
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return result;
}
//! registers a node for rendering it at a specific time.
u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDER_PASS pass)
{
u32 taken = 0;
switch(pass)
{
// take camera if it is not already registered
case ESNRP_CAMERA:
{
taken = 1;
for (u32 i = 0; i != CameraList.size(); ++i)
{
if (CameraList[i] == node)
{
taken = 0;
break;
}
}
if (taken)
{
CameraList.push_back(node);
}
}
break;
case ESNRP_LIGHT:
// TODO: Point Light culling..
// Lighting model in irrlicht has to be redone..
//if (!isCulled(node))
{
LightList.push_back(node);
taken = 1;
}
break;
case ESNRP_SKY_BOX:
SkyBoxList.push_back(node);
taken = 1;
break;
case ESNRP_SOLID:
if (!isCulled(node))
{
SolidNodeList.push_back(node);
taken = 1;
}
break;
case ESNRP_TRANSPARENT:
if (!isCulled(node))
{
TransparentNodeList.push_back(TransparentNodeEntry(node, camWorldPos));
taken = 1;
}
break;
case ESNRP_TRANSPARENT_EFFECT:
if (!isCulled(node))
{
TransparentEffectNodeList.push_back(TransparentNodeEntry(node, camWorldPos));
taken = 1;
}
break;
case ESNRP_AUTOMATIC:
if (!isCulled(node))
{
const u32 count = node->getMaterialCount();
taken = 0;
for (u32 i=0; i<count; ++i)
{
video::IMaterialRenderer* rnd =
Driver->getMaterialRenderer(node->getMaterial(i).MaterialType);
if (rnd && rnd->isTransparent())
{
// register as transparent node
TransparentNodeEntry e(node, camWorldPos);
TransparentNodeList.push_back(e);
taken = 1;
break;
}
}
// not transparent, register as solid
if (!taken)
{
SolidNodeList.push_back(node);
taken = 1;
}
}
break;
case ESNRP_SHADOW:
if (!isCulled(node))
{
ShadowNodeList.push_back(node);
taken = 1;
}
break;
case ESNRP_NONE: // ignore this one
break;
}
#ifdef _IRR_SCENEMANAGER_DEBUG
s32 index = Parameters.findAttribute ( "calls" );
Parameters.setAttribute ( index, Parameters.getAttributeAsInt ( index ) + 1 );
if (!taken)
{
index = Parameters.findAttribute ( "culled" );
Parameters.setAttribute ( index, Parameters.getAttributeAsInt ( index ) + 1 );
}
#endif
return taken;
}
//! This method is called just before the rendering process of the whole scene.
//! draws all scene nodes
void CSceneManager::drawAll()
{
if (!Driver)
return;
#ifdef _IRR_SCENEMANAGER_DEBUG
// reset attributes
Parameters.setAttribute ( "culled", 0 );
Parameters.setAttribute ( "calls", 0 );
Parameters.setAttribute ( "drawn_solid", 0 );
Parameters.setAttribute ( "drawn_transparent", 0 );
Parameters.setAttribute ( "drawn_transparent_effect", 0 );
#endif
u32 i; // new ISO for scoping problem in some compilers
// reset all transforms
Driver->setMaterial(video::SMaterial());
Driver->setTransform ( video::ETS_PROJECTION, core::IdentityMatrix );
Driver->setTransform ( video::ETS_VIEW, core::IdentityMatrix );
Driver->setTransform ( video::ETS_WORLD, core::IdentityMatrix );
for (i=video::ETS_COUNT-1; i>=video::ETS_TEXTURE_0; --i)
Driver->setTransform ( (video::E_TRANSFORMATION_STATE)i, core::IdentityMatrix );
// TODO: This should not use an attribute here but a real parameter when necessary (too slow!)
Driver->setAllowZWriteOnTransparent(Parameters.getAttributeAsBool( ALLOW_ZWRITE_ON_TRANSPARENT) );
// do animations and other stuff.
OnAnimate(os::Timer::getTime());
/*!
First Scene Node for prerendering should be the active camera
consistent Camera is needed for culling
*/
camWorldPos.set(0,0,0);
if (ActiveCamera)
{
ActiveCamera->render();
camWorldPos = ActiveCamera->getAbsolutePosition();
}
// let all nodes register themselves
OnRegisterSceneNode();
if (LightManager)
LightManager->OnPreRender(LightList);
//render camera scenes
{
CurrentRendertime = ESNRP_CAMERA;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
if (LightManager)
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<CameraList.size(); ++i)
CameraList[i]->render();
CameraList.set_used(0);
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
//render lights scenes
{
CurrentRendertime = ESNRP_LIGHT;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
}
else
{
// Sort the lights by distance from the camera
core::vector3df camWorldPos(0, 0, 0);
if (ActiveCamera)
camWorldPos = ActiveCamera->getAbsolutePosition();
core::array<DistanceNodeEntry> SortedLights;
SortedLights.set_used(LightList.size());
for (s32 light = (s32)LightList.size() - 1; light >= 0; --light)
SortedLights[light].setNodeAndDistanceFromPosition(LightList[light], camWorldPos);
SortedLights.set_sorted(false);
SortedLights.sort();
for(s32 light = (s32)LightList.size() - 1; light >= 0; --light)
LightList[light] = SortedLights[light].Node;
}
Driver->deleteAllDynamicLights();
Driver->setAmbientLight(AmbientLight);
u32 maxLights = LightList.size();
if (!LightManager)
maxLights = core::min_ ( Driver->getMaximalDynamicLightAmount(), maxLights);
for (i=0; i< maxLights; ++i)
LightList[i]->render();
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
// render skyboxes
{
CurrentRendertime = ESNRP_SKY_BOX;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<SkyBoxList.size(); ++i)
{
ISceneNode* node = SkyBoxList[i];
LightManager->OnNodePreRender(node);
node->render();
LightManager->OnNodePostRender(node);
}
}
else
{
for (i=0; i<SkyBoxList.size(); ++i)
SkyBoxList[i]->render();
}
SkyBoxList.set_used(0);
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
// render default objects
{
CurrentRendertime = ESNRP_SOLID;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
SolidNodeList.sort(); // sort by textures
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<SolidNodeList.size(); ++i)
{
ISceneNode* node = SolidNodeList[i].Node;
LightManager->OnNodePreRender(node);
node->render();
LightManager->OnNodePostRender(node);
}
}
else
{
for (i=0; i<SolidNodeList.size(); ++i)
SolidNodeList[i].Node->render();
}
#ifdef _IRR_SCENEMANAGER_DEBUG
Parameters.setAttribute("drawn_solid", (s32) SolidNodeList.size() );
#endif
SolidNodeList.set_used(0);
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
// render shadows
{
CurrentRendertime = ESNRP_SHADOW;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<ShadowNodeList.size(); ++i)
{
ISceneNode* node = ShadowNodeList[i];
LightManager->OnNodePreRender(node);
node->render();
LightManager->OnNodePostRender(node);
}
}
else
{
for (i=0; i<ShadowNodeList.size(); ++i)
ShadowNodeList[i]->render();
}
if (!ShadowNodeList.empty())
Driver->drawStencilShadow(true,ShadowColor, ShadowColor,
ShadowColor, ShadowColor);
ShadowNodeList.set_used(0);
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
// render transparent objects.
{
CurrentRendertime = ESNRP_TRANSPARENT;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
TransparentNodeList.sort(); // sort by distance from camera
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<TransparentNodeList.size(); ++i)
{
ISceneNode* node = TransparentNodeList[i].Node;
LightManager->OnNodePreRender(node);
node->render();
LightManager->OnNodePostRender(node);
}
}
else
{
for (i=0; i<TransparentNodeList.size(); ++i)
TransparentNodeList[i].Node->render();
}
#ifdef _IRR_SCENEMANAGER_DEBUG
Parameters.setAttribute ( "drawn_transparent", (s32) TransparentNodeList.size() );
#endif
TransparentNodeList.set_used(0);
if (LightManager)
LightManager->OnRenderPassPostRender(CurrentRendertime);
}
// render transparent effect objects.
{
CurrentRendertime = ESNRP_TRANSPARENT_EFFECT;
Driver->getOverrideMaterial().Enabled = ((Driver->getOverrideMaterial().EnablePasses & CurrentRendertime) != 0);
TransparentEffectNodeList.sort(); // sort by distance from camera
if (LightManager)
{
LightManager->OnRenderPassPreRender(CurrentRendertime);
for (i=0; i<TransparentEffectNodeList.size(); ++i)
{
ISceneNode* node = TransparentEffectNodeList[i].Node;
LightManager->OnNodePreRender(node);
node->render();
LightManager->OnNodePostRender(node);
}
}
else
{
for (i=0; i<TransparentEffectNodeList.size(); ++i)
TransparentEffectNodeList[i].Node->render();
}
#ifdef _IRR_SCENEMANAGER_DEBUG
Parameters.setAttribute ( "drawn_transparent_effect", (s32) TransparentEffectNodeList.size() );
#endif
TransparentEffectNodeList.set_used(0);
}
if (LightManager)
LightManager->OnPostRender();
LightList.set_used(0);
clearDeletionList();
CurrentRendertime = ESNRP_NONE;
}
void CSceneManager::setLightManager(ILightManager* lightManager)
{
if (lightManager)
lightManager->grab();
if (LightManager)
LightManager->drop();
LightManager = lightManager;
}
//! Sets the color of stencil buffers shadows drawn by the scene manager.
void CSceneManager::setShadowColor(video::SColor color)
{
ShadowColor = color;
}
//! Returns the current color of shadows.
video::SColor CSceneManager::getShadowColor() const
{
return ShadowColor;
}
//! creates a rotation animator, which rotates the attached scene node around itself.
ISceneNodeAnimator* CSceneManager::createRotationAnimator(const core::vector3df& rotationPerSecond)
{
ISceneNodeAnimator* anim = new CSceneNodeAnimatorRotation(os::Timer::getTime(),
rotationPerSecond);
return anim;
}
//! creates a fly circle animator, which lets the attached scene node fly around a center.
ISceneNodeAnimator* CSceneManager::createFlyCircleAnimator(
const core::vector3df& center, f32 radius, f32 speed,
const core::vector3df& direction,
f32 startPosition,
f32 radiusEllipsoid)
{
const f32 orbitDurationMs = (core::DEGTORAD * 360.f) / speed;
const u32 effectiveTime = os::Timer::getTime() + (u32)(orbitDurationMs * startPosition);
ISceneNodeAnimator* anim = new CSceneNodeAnimatorFlyCircle(
effectiveTime, center,
radius, speed, direction,radiusEllipsoid);
return anim;
}
//! Creates a fly straight animator, which lets the attached scene node
//! fly or move along a line between two points.
ISceneNodeAnimator* CSceneManager::createFlyStraightAnimator(const core::vector3df& startPoint,
const core::vector3df& endPoint, u32 timeForWay, bool loop,bool pingpong)
{
ISceneNodeAnimator* anim = new CSceneNodeAnimatorFlyStraight(startPoint,
endPoint, timeForWay, loop, os::Timer::getTime(), pingpong);
return anim;
}
//! Creates a texture animator, which switches the textures of the target scene
//! node based on a list of textures.
ISceneNodeAnimator* CSceneManager::createTextureAnimator(const core::array<video::ITexture*>& textures,
s32 timePerFrame, bool loop)
{
ISceneNodeAnimator* anim = new CSceneNodeAnimatorTexture(textures,
timePerFrame, loop, os::Timer::getTime());
return anim;
}
//! Creates a scene node animator, which deletes the scene node after
//! some time automaticly.
ISceneNodeAnimator* CSceneManager::createDeleteAnimator(u32 when)
{
return new CSceneNodeAnimatorDelete(this, os::Timer::getTime() + when);
}
//! Creates a special scene node animator for doing automatic collision detection
//! and response.
ISceneNodeAnimatorCollisionResponse* CSceneManager::createCollisionResponseAnimator(
ITriangleSelector* world, ISceneNode* sceneNode, const core::vector3df& ellipsoidRadius,
const core::vector3df& gravityPerSecond,
const core::vector3df& ellipsoidTranslation, f32 slidingValue)
{
ISceneNodeAnimatorCollisionResponse* anim = new
CSceneNodeAnimatorCollisionResponse(this, world, sceneNode,
ellipsoidRadius, gravityPerSecond,
ellipsoidTranslation, slidingValue);
return anim;
}
//! Creates a follow spline animator.
ISceneNodeAnimator* CSceneManager::createFollowSplineAnimator(s32 startTime,
const core::array< core::vector3df >& points,
f32 speed, f32 tightness, bool loop, bool pingpong)
{
ISceneNodeAnimator* a = new CSceneNodeAnimatorFollowSpline(startTime, points,
speed, tightness, loop, pingpong);
return a;
}
//! Adds an external mesh loader.
void CSceneManager::addExternalMeshLoader(IMeshLoader* externalLoader)
{
if (!externalLoader)
return;
externalLoader->grab();
MeshLoaderList.push_back(externalLoader);
}
//! Returns the number of mesh loaders supported by Irrlicht at this time
u32 CSceneManager::getMeshLoaderCount() const
{
return MeshLoaderList.size();
}
//! Retrieve the given mesh loader
IMeshLoader* CSceneManager::getMeshLoader(u32 index) const
{
if (index < MeshLoaderList.size())
return MeshLoaderList[index];
else
return 0;
}
//! Adds an external scene loader.
void CSceneManager::addExternalSceneLoader(ISceneLoader* externalLoader)
{
if (!externalLoader)
return;
externalLoader->grab();
SceneLoaderList.push_back(externalLoader);
}
//! Returns the number of scene loaders
u32 CSceneManager::getSceneLoaderCount() const
{
return SceneLoaderList.size();
}
//! Retrieve the given scene loader
ISceneLoader* CSceneManager::getSceneLoader(u32 index) const
{
if (index < SceneLoaderList.size())
return SceneLoaderList[index];
else
return 0;
}
//! Returns a pointer to the scene collision manager.
ISceneCollisionManager* CSceneManager::getSceneCollisionManager()
{
return CollisionManager;
}
//! Returns a pointer to the mesh manipulator.
IMeshManipulator* CSceneManager::getMeshManipulator()
{
return Driver->getMeshManipulator();
}
//! Creates a simple ITriangleSelector, based on a mesh.
ITriangleSelector* CSceneManager::createTriangleSelector(IMesh* mesh, ISceneNode* node)
{
if (!mesh)
return 0;
return new CTriangleSelector(mesh, node);
}
//! Creates a simple and updatable ITriangleSelector, based on a the mesh owned by an
//! animated scene node
ITriangleSelector* CSceneManager::createTriangleSelector(IAnimatedMeshSceneNode* node)
{
if (!node || !node->getMesh())
return 0;
return new CTriangleSelector(node);
}
//! Creates a simple dynamic ITriangleSelector, based on a axis aligned bounding box.
ITriangleSelector* CSceneManager::createTriangleSelectorFromBoundingBox(ISceneNode* node)
{
if (!node)
return 0;
return new CTriangleBBSelector(node);
}
//! Creates a simple ITriangleSelector, based on a mesh.
ITriangleSelector* CSceneManager::createOctreeTriangleSelector(IMesh* mesh,
ISceneNode* node, s32 minimalPolysPerNode)
{
if (!mesh)
return 0;
return new COctreeTriangleSelector(mesh, node, minimalPolysPerNode);
}
//! Creates a meta triangle selector.
IMetaTriangleSelector* CSceneManager::createMetaTriangleSelector()
{
return new CMetaTriangleSelector();
}
//! Creates a triangle selector which can select triangles from a terrain scene node
ITriangleSelector* CSceneManager::createTerrainTriangleSelector(
ITerrainSceneNode* node, s32 LOD)
{
return new CTerrainTriangleSelector(node, LOD);
}
//! Adds a scene node to the deletion queue.
void CSceneManager::addToDeletionQueue(ISceneNode* node)
{
if (!node)
return;
node->grab();
DeletionList.push_back(node);
}
//! clears the deletion list
void CSceneManager::clearDeletionList()
{
if (DeletionList.empty())
return;
for (u32 i=0; i<DeletionList.size(); ++i)
{
DeletionList[i]->remove();
DeletionList[i]->drop();
}
DeletionList.clear();
}
//! Returns the first scene node with the specified name.
ISceneNode* CSceneManager::getSceneNodeFromName(const char* name, ISceneNode* start)
{
if (start == 0)
start = getRootSceneNode();
if (!strcmp(start->getName(),name))
return start;
ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromName(name, *it);
if (node)
return node;
}
return 0;
}
//! Returns the first scene node with the specified id.
ISceneNode* CSceneManager::getSceneNodeFromId(s32 id, ISceneNode* start)
{
if (start == 0)
start = getRootSceneNode();
if (start->getID() == id)
return start;
ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromId(id, *it);
if (node)
return node;
}
return 0;
}
//! Returns the first scene node with the specified type.
ISceneNode* CSceneManager::getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode* start)
{
if (start == 0)
start = getRootSceneNode();
if (start->getType() == type || ESNT_ANY == type)
return start;
ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
node = getSceneNodeFromType(type, *it);
if (node)
return node;
}
return 0;
}
//! returns scene nodes by type.
void CSceneManager::getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<scene::ISceneNode*>& outNodes, ISceneNode* start)
{
if (start == 0)
start = getRootSceneNode();
if (start->getType() == type || ESNT_ANY == type)
outNodes.push_back(start);
const ISceneNodeList& list = start->getChildren();
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{
getSceneNodesFromType(type, outNodes, *it);
}
}
//! Posts an input event to the environment. Usually you do not have to
//! use this method, it is used by the internal engine.
bool CSceneManager::postEventFromUser(const SEvent& event)
{
bool ret = false;
ICameraSceneNode* cam = getActiveCamera();
if (cam)
ret = cam->OnEvent(event);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
//! Removes all children of this scene node
void CSceneManager::removeAll()
{
ISceneNode::removeAll();
setActiveCamera(0);
// Make sure the driver is reset, might need a more complex method at some point
if (Driver)
Driver->setMaterial(video::SMaterial());
}
//! Clears the whole scene. All scene nodes are removed.
void CSceneManager::clear()
{
removeAll();
}
//! Returns interface to the parameters set in this scene.
io::IAttributes* CSceneManager::getParameters()
{
return &Parameters;
}
//! Returns current render pass.
E_SCENE_NODE_RENDER_PASS CSceneManager::getSceneNodeRenderPass() const
{
return CurrentRendertime;
}
//! Returns an interface to the mesh cache which is shared beween all existing scene managers.
IMeshCache* CSceneManager::getMeshCache()
{
return MeshCache;
}
//! Creates a new scene manager.
ISceneManager* CSceneManager::createNewSceneManager(bool cloneContent)
{
CSceneManager* manager = new CSceneManager(Driver, FileSystem, CursorControl, MeshCache, GUIEnvironment);
if (cloneContent)
manager->cloneMembers(this, manager);
return manager;
}
//! Returns the default scene node factory which can create all built in scene nodes
ISceneNodeFactory* CSceneManager::getDefaultSceneNodeFactory()
{
return getSceneNodeFactory(0);
}
//! Adds a scene node factory to the scene manager.
void CSceneManager::registerSceneNodeFactory(ISceneNodeFactory* factoryToAdd)
{
if (factoryToAdd)
{
factoryToAdd->grab();
SceneNodeFactoryList.push_back(factoryToAdd);
}
}
//! Returns amount of registered scene node factories.
u32 CSceneManager::getRegisteredSceneNodeFactoryCount() const
{
return SceneNodeFactoryList.size();
}
//! Returns a scene node factory by index
ISceneNodeFactory* CSceneManager::getSceneNodeFactory(u32 index)
{
if (index < SceneNodeFactoryList.size())
return SceneNodeFactoryList[index];
return 0;
}
//! Returns the default scene node animator factory which can create all built-in scene node animators
ISceneNodeAnimatorFactory* CSceneManager::getDefaultSceneNodeAnimatorFactory()
{
return getSceneNodeAnimatorFactory(0);
}
//! Adds a scene node animator factory to the scene manager.
void CSceneManager::registerSceneNodeAnimatorFactory(ISceneNodeAnimatorFactory* factoryToAdd)
{
if (factoryToAdd)
{
factoryToAdd->grab();
SceneNodeAnimatorFactoryList.push_back(factoryToAdd);
}
}
//! Returns amount of registered scene node animator factories.
u32 CSceneManager::getRegisteredSceneNodeAnimatorFactoryCount() const
{
return SceneNodeAnimatorFactoryList.size();
}
//! Returns a scene node animator factory by index
ISceneNodeAnimatorFactory* CSceneManager::getSceneNodeAnimatorFactory(u32 index)
{
if (index < SceneNodeAnimatorFactoryList.size())
return SceneNodeAnimatorFactoryList[index];
return 0;
}
//! Saves the current scene into a file.
//! \param filename: Name of the file .
bool CSceneManager::saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node)
{
bool ret = false;
io::IWriteFile* file = FileSystem->createAndWriteFile(filename);
if (file)
{
ret = saveScene(file, userDataSerializer, node);
file->drop();
}
else
os::Printer::log("Unable to open file", filename, ELL_ERROR);
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return ret;
}
//! Saves the current scene into a file.
bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node)
{
if (!file)
{
return false;
}
bool result=false;
io::IXMLWriter* writer = FileSystem->createXMLWriter(file);
if (!writer)
{
os::Printer::log("Unable to create XML writer", file->getFileName(), ELL_ERROR);
}
else
{
result = saveScene(writer, FileSystem->getFileDir(FileSystem->getAbsolutePath(file->getFileName())), userDataSerializer, node);
writer->drop();
}
return result;
}
//! Saves the current scene into a file.
bool CSceneManager::saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node)
{
if (!writer)
return false;
if (!node)
node=this;
writer->writeXMLHeader();
writeSceneNode(writer, node, userDataSerializer, currentPath.c_str(), true);
return true;
}
//! Loads a scene.
bool CSceneManager::loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer, ISceneNode* rootNode)
{
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (!file)
{
os::Printer::log("Unable to open scene file", filename.c_str(), ELL_ERROR);
return false;
}
const bool ret = loadScene(file, userDataSerializer, rootNode);
file->drop();
return ret;
}
//! Loads a scene. Note that the current scene is not cleared before.
bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer, ISceneNode* rootNode)
{
if (!file)
{
os::Printer::log("Unable to open scene file", ELL_ERROR);
return false;
}
bool ret = false;
// try scene loaders in reverse order
s32 i = SceneLoaderList.size()-1;
for (; i >= 0 && !ret; --i)
if (SceneLoaderList[i]->isALoadableFileFormat(file))
ret = SceneLoaderList[i]->loadScene(file, userDataSerializer, rootNode);
if (!ret)
os::Printer::log("Could not load scene file, perhaps the format is unsupported: ", file->getFileName().c_str(), ELL_ERROR);
return ret;
}
//! writes a scene node
void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer,
const fschar_t* currentPath, bool init)
{
if (!writer || !node || node->isDebugObject())
return;
const wchar_t* name;
ISceneNode* tmpNode=node;
if (init)
{
name = IRR_XML_FORMAT_SCENE.c_str();
writer->writeElement(name, false);
node=this;
}
else
{
name = IRR_XML_FORMAT_NODE.c_str();
writer->writeElement(name, false, IRR_XML_FORMAT_NODE_ATTR_TYPE.c_str(),
core::stringw(getSceneNodeTypeName(node->getType())).c_str());
}
writer->writeLineBreak();
// write properties
io::IAttributes* attr = FileSystem->createEmptyAttributes(Driver);
io::SAttributeReadWriteOptions options;
if (currentPath)
{
options.Filename=currentPath;
options.Flags|=io::EARWF_USE_RELATIVE_PATHS;
}
node->serializeAttributes(attr, &options);
if (attr->getAttributeCount() != 0)
{
attr->write(writer);
writer->writeLineBreak();
}
// write materials
if (node->getMaterialCount() && Driver)
{
const wchar_t* materialElement = L"materials";
writer->writeElement(materialElement);
writer->writeLineBreak();
for (u32 i=0; i < node->getMaterialCount(); ++i)
{
io::IAttributes* tmp_attr =
Driver->createAttributesFromMaterial(node->getMaterial(i), &options);
tmp_attr->write(writer);
tmp_attr->drop();
}
writer->writeClosingTag(materialElement);
writer->writeLineBreak();
}
// write animators
if (!node->getAnimators().empty())
{
const wchar_t* animatorElement = L"animators";
writer->writeElement(animatorElement);
writer->writeLineBreak();
ISceneNodeAnimatorList::ConstIterator it = node->getAnimators().begin();
for (; it != node->getAnimators().end(); ++it)
{
attr->clear();
attr->addString("Type", getAnimatorTypeName((*it)->getType()));
(*it)->serializeAttributes(attr);
attr->write(writer);
}
writer->writeClosingTag(animatorElement);
writer->writeLineBreak();
}
// write possible user data
if (userDataSerializer)
{
io::IAttributes* userData = userDataSerializer->createUserData(node);
if (userData)
{
const wchar_t* userDataElement = L"userData";
writer->writeLineBreak();
writer->writeElement(userDataElement);
writer->writeLineBreak();
userData->write(writer);
writer->writeClosingTag(userDataElement);
writer->writeLineBreak();
writer->writeLineBreak();
userData->drop();
}
}
// reset to actual root node
if (init)
node=tmpNode;
// write children once root node is written
// if parent is not scene manager, we need to write out node first
if (init && (node != this))
{
writeSceneNode(writer, node, userDataSerializer, currentPath);
}
else
{
ISceneNodeList::ConstIterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); ++it)
writeSceneNode(writer, (*it), userDataSerializer, currentPath);
}
attr->drop();
writer->writeClosingTag(name);
writer->writeLineBreak();
writer->writeLineBreak();
}
//! Returns a typename from a scene node type or null if not found
const c8* CSceneManager::getSceneNodeTypeName(ESCENE_NODE_TYPE type)
{
const char* name = 0;
for (s32 i=(s32)SceneNodeFactoryList.size()-1; !name && i>=0; --i)
name = SceneNodeFactoryList[i]->getCreateableSceneNodeTypeName(type);
return name;
}
//! Adds a scene node to the scene by name
ISceneNode* CSceneManager::addSceneNode(const char* sceneNodeTypeName, ISceneNode* parent)
{
ISceneNode* node = 0;
for (s32 i=(s32)SceneNodeFactoryList.size()-1; i>=0 && !node; --i)
node = SceneNodeFactoryList[i]->addSceneNode(sceneNodeTypeName, parent);
return node;
}
ISceneNodeAnimator* CSceneManager::createSceneNodeAnimator(const char* typeName, ISceneNode* target)
{
ISceneNodeAnimator *animator = 0;
for (s32 i=(s32)SceneNodeAnimatorFactoryList.size()-1; i>=0 && !animator; --i)
animator = SceneNodeAnimatorFactoryList[i]->createSceneNodeAnimator(typeName, target);
return animator;
}
//! Returns a typename from a scene node animator type or null if not found
const c8* CSceneManager::getAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type)
{
const char* name = 0;
for (s32 i=SceneNodeAnimatorFactoryList.size()-1; !name && i >= 0; --i)
name = SceneNodeAnimatorFactoryList[i]->getCreateableSceneNodeAnimatorTypeName(type);
return name;
}
//! Writes attributes of the scene node.
void CSceneManager::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
out->addString ("Name", Name.c_str());
out->addInt ("Id", ID );
out->addColorf ("AmbientLight", AmbientLight);
// fog attributes from video driver
video::SColor color;
video::E_FOG_TYPE fogType;
f32 start, end, density;
bool pixelFog, rangeFog;
Driver->getFog(color, fogType, start, end, density, pixelFog, rangeFog);
out->addEnum("FogType", fogType, video::FogTypeNames);
out->addColorf("FogColor", color);
out->addFloat("FogStart", start);
out->addFloat("FogEnd", end);
out->addFloat("FogDensity", density);
out->addBool("FogPixel", pixelFog);
out->addBool("FogRange", rangeFog);
}
//! Reads attributes of the scene node.
void CSceneManager::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
Name = in->getAttributeAsString("Name");
ID = in->getAttributeAsInt("Id");
AmbientLight = in->getAttributeAsColorf("AmbientLight");
// fog attributes
video::SColor color;
video::E_FOG_TYPE fogType;
f32 start, end, density;
bool pixelFog, rangeFog;
if (in->existsAttribute("FogType"))
{
fogType = (video::E_FOG_TYPE) in->getAttributeAsEnumeration("FogType", video::FogTypeNames);
color = in->getAttributeAsColorf("FogColor").toSColor();
start = in->getAttributeAsFloat("FogStart");
end = in->getAttributeAsFloat("FogEnd");
density = in->getAttributeAsFloat("FogDensity");
pixelFog = in->getAttributeAsBool("FogPixel");
rangeFog = in->getAttributeAsBool("FogRange");
Driver->setFog(color, fogType, start, end, density, pixelFog, rangeFog);
}
RelativeTranslation.set(0,0,0);
RelativeRotation.set(0,0,0);
RelativeScale.set(1,1,1);
IsVisible = true;
AutomaticCullingState = scene::EAC_BOX;
DebugDataVisible = scene::EDS_OFF;
IsDebugObject = false;
updateAbsolutePosition();
}
//! Sets ambient color of the scene
void CSceneManager::setAmbientLight(const video::SColorf &ambientColor)
{
AmbientLight = ambientColor;
}
//! Returns ambient color of the scene
const video::SColorf& CSceneManager::getAmbientLight() const
{
return AmbientLight;
}
//! Get a skinned mesh, which is not available as header-only code
ISkinnedMesh* CSceneManager::createSkinnedMesh()
{
#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
return new CSkinnedMesh();
#else
return 0;
#endif
}
//! Returns a mesh writer implementation if available
IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type)
{
switch(type)
{
case EMWT_IRR_MESH:
#ifdef _IRR_COMPILE_WITH_IRR_WRITER_
return new CIrrMeshWriter(Driver, FileSystem);
#else
return 0;
#endif
case EMWT_COLLADA:
#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_
return new CColladaMeshWriter(this, Driver, FileSystem);
#else
return 0;
#endif
case EMWT_STL:
#ifdef _IRR_COMPILE_WITH_STL_WRITER_
return new CSTLMeshWriter(this);
#else
return 0;
#endif
case EMWT_OBJ:
#ifdef _IRR_COMPILE_WITH_OBJ_WRITER_
return new COBJMeshWriter(this, FileSystem);
#else
return 0;
#endif
case EMWT_PLY:
#ifdef _IRR_COMPILE_WITH_PLY_WRITER_
return new CPLYMeshWriter();
#else
return 0;
#endif
}
return 0;
}
// creates a scenemanager
ISceneManager* createSceneManager(video::IVideoDriver* driver,
io::IFileSystem* fs, gui::ICursorControl* cursorcontrol,
gui::IGUIEnvironment *guiEnvironment)
{
return new CSceneManager(driver, fs, cursorcontrol, 0, guiEnvironment );
}
} // end namespace scene
} // end namespace irr
|