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
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/blenkernel/intern/scene.c
* \ingroup bke
*/
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_group_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_sequence_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_gpencil_types.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLI_callbacks.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_threads.h"
#include "BLI_task.h"
#include "BLT_translation.h"
#include "BKE_anim.h"
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_cachefile.h"
#include "BKE_collection.h"
#include "BKE_colortools.h"
#include "BKE_editmesh.h"
#include "BKE_fcurve.h"
#include "BKE_freestyle.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_group.h"
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
#include "BKE_main.h"
#include "BKE_mask.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_paint.h"
#include "BKE_rigidbody.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
#include "BKE_sound.h"
#include "BKE_unit.h"
#include "BKE_workspace.h"
#include "BKE_world.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "RE_engine.h"
#include "PIL_time.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "bmesh.h"
const char *RE_engine_id_BLENDER_RENDER = "BLENDER_RENDER";
const char *RE_engine_id_BLENDER_GAME = "BLENDER_GAME";
const char *RE_engine_id_BLENDER_CLAY = "BLENDER_CLAY";
const char *RE_engine_id_BLENDER_EEVEE = "BLENDER_EEVEE";
const char *RE_engine_id_CYCLES = "CYCLES";
void free_avicodecdata(AviCodecData *acd)
{
if (acd) {
if (acd->lpFormat) {
MEM_freeN(acd->lpFormat);
acd->lpFormat = NULL;
acd->cbFormat = 0;
}
if (acd->lpParms) {
MEM_freeN(acd->lpParms);
acd->lpParms = NULL;
acd->cbParms = 0;
}
}
}
void free_qtcodecdata(QuicktimeCodecData *qcd)
{
if (qcd) {
if (qcd->cdParms) {
MEM_freeN(qcd->cdParms);
qcd->cdParms = NULL;
qcd->cdSize = 0;
}
}
}
static void remove_sequencer_fcurves(Scene *sce)
{
AnimData *adt = BKE_animdata_from_id(&sce->id);
if (adt && adt->action) {
FCurve *fcu, *nextfcu;
for (fcu = adt->action->curves.first; fcu; fcu = nextfcu) {
nextfcu = fcu->next;
if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
action_groups_remove_channel(adt->action, fcu);
free_fcurve(fcu);
}
}
}
}
/* copy SceneCollection tree but keep pointing to the same objects */
static void scene_collection_copy(SceneCollection *scn, SceneCollection *sc)
{
BLI_duplicatelist(&scn->objects, &sc->objects);
for (LinkData *link = scn->objects.first; link; link = link->next) {
id_us_plus(link->data);
}
BLI_duplicatelist(&scn->filter_objects, &sc->filter_objects);
for (LinkData *link = scn->filter_objects.first; link; link = link->next) {
id_us_plus(link->data);
}
BLI_duplicatelist(&scn->scene_collections, &sc->scene_collections);
SceneCollection *nscn = scn->scene_collections.first; /* nested SceneCollection new */
for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
scene_collection_copy(nscn, nsc);
nscn = nscn->next;
}
}
/* Find the equivalent SceneCollection in the new tree */
static SceneCollection *scene_collection_from_new_tree(SceneCollection *sc_reference, SceneCollection *scn, SceneCollection *sc)
{
if (sc == sc_reference) {
return scn;
}
SceneCollection *nscn = scn->scene_collections.first; /* nested master collection new */
for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
SceneCollection *found = scene_collection_from_new_tree(sc_reference, nscn, nsc);
if (found) {
return found;
}
nscn = nscn->next;
}
return NULL;
}
/* recreate the LayerCollection tree */
static void layer_collections_recreate(SceneLayer *sl, ListBase *lb, SceneCollection *mcn, SceneCollection *mc)
{
for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
SceneCollection *sc = scene_collection_from_new_tree(lc->scene_collection, mcn, mc);
BLI_assert(sc);
/* instead of syncronizing both trees we simply re-create it */
BKE_collection_link(sl, sc);
}
}
/**
* Only copy internal data of Scene ID from source to already allocated/initialized destination.
* You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
*
* WARNING! This function will not handle ID user count!
*
* \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
*/
void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, const int flag)
{
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
sce_dst->ed = NULL;
sce_dst->theDag = NULL;
sce_dst->depsgraph_legacy = NULL;
sce_dst->obedit = NULL;
sce_dst->fps_info = NULL;
BLI_duplicatelist(&(sce_dst->base), &(sce_src->base));
for (BaseLegacy *base_dst = sce_dst->base.first, *base_src = sce_src->base.first;
base_dst;
base_dst = base_dst->next, base_src = base_src->next)
{
if (base_src == sce_src->basact) {
sce_dst->basact = base_dst;
}
}
/* layers and collections */
sce_dst->collection = MEM_dupallocN(sce_src->collection);
SceneCollection *mcn = BKE_collection_master(sce_dst);
SceneCollection *mc = BKE_collection_master(sce_src);
/* recursively creates a new SceneCollection tree */
scene_collection_copy(mcn, mc);
IDPropertyTemplate val = {0};
BLI_duplicatelist(&sce_dst->render_layers, &sce_src->render_layers);
SceneLayer *new_sl = sce_dst->render_layers.first;
for (SceneLayer *sl = sce_src->render_layers.first; sl; sl = sl->next) {
new_sl->stats = NULL;
new_sl->properties_evaluated = NULL;
new_sl->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
IDP_MergeGroup(new_sl->properties, sl->properties, true);
/* we start fresh with no overrides and no visibility flags set
* instead of syncing both trees we simply unlink and relink the scene collection */
BLI_listbase_clear(&new_sl->layer_collections);
BLI_listbase_clear(&new_sl->object_bases);
BLI_listbase_clear(&new_sl->drawdata);
layer_collections_recreate(new_sl, &sl->layer_collections, mcn, mc);
Object *active_ob = OBACT_NEW;
Base *new_base = new_sl->object_bases.first;
for (Base *base = sl->object_bases.first; base; base = base->next) {
new_base->flag = base->flag;
new_base->flag_legacy = base->flag_legacy;
if (new_base->object == active_ob) {
new_sl->basact = new_base;
}
new_base = new_base->next;
}
new_sl = new_sl->next;
}
sce_dst->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
sce_dst->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BLI_duplicatelist(&(sce_dst->markers), &(sce_src->markers));
BLI_duplicatelist(&(sce_dst->r.layers), &(sce_src->r.layers));
BLI_duplicatelist(&(sce_dst->r.views), &(sce_src->r.views));
BKE_keyingsets_copy(&(sce_dst->keyingsets), &(sce_src->keyingsets));
if (sce_src->nodetree) {
BKE_id_copy_ex(bmain, (ID *)sce_src->nodetree, (ID **)&sce_dst->nodetree, flag, false);
BKE_libblock_relink_ex(bmain, sce_dst->nodetree, (void *)(&sce_src->id), &sce_dst->id, false);
}
if (sce_src->rigidbody_world) {
sce_dst->rigidbody_world = BKE_rigidbody_world_copy(sce_src->rigidbody_world, flag_subdata);
}
/* copy Freestyle settings */
for (SceneRenderLayer *srl_dst = sce_dst->r.layers.first, *srl_src = sce_src->r.layers.first;
srl_src;
srl_dst = srl_dst->next, srl_src = srl_src->next)
{
if (srl_dst->prop != NULL) {
srl_dst->prop = IDP_CopyProperty_ex(srl_dst->prop, flag_subdata);
}
BKE_freestyle_config_copy(&srl_dst->freestyleConfig, &srl_src->freestyleConfig, flag_subdata);
}
/* copy color management settings */
BKE_color_managed_display_settings_copy(&sce_dst->display_settings, &sce_src->display_settings);
BKE_color_managed_view_settings_copy(&sce_dst->view_settings, &sce_src->view_settings);
BKE_color_managed_colorspace_settings_copy(&sce_dst->sequencer_colorspace_settings, &sce_src->sequencer_colorspace_settings);
BKE_color_managed_display_settings_copy(&sce_dst->r.im_format.display_settings, &sce_src->r.im_format.display_settings);
BKE_color_managed_view_settings_copy(&sce_dst->r.im_format.view_settings, &sce_src->r.im_format.view_settings);
BKE_color_managed_display_settings_copy(&sce_dst->r.bake.im_format.display_settings, &sce_src->r.bake.im_format.display_settings);
BKE_color_managed_view_settings_copy(&sce_dst->r.bake.im_format.view_settings, &sce_src->r.bake.im_format.view_settings);
curvemapping_copy_data(&sce_dst->r.mblur_shutter_curve, &sce_src->r.mblur_shutter_curve);
/* tool settings */
if (sce_dst->toolsettings != NULL) {
ToolSettings *ts = sce_dst->toolsettings = MEM_dupallocN(sce_dst->toolsettings);
if (ts->vpaint) {
ts->vpaint = MEM_dupallocN(ts->vpaint);
ts->vpaint->paintcursor = NULL;
ts->vpaint->vpaint_prev = NULL;
ts->vpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag_subdata);
}
if (ts->wpaint) {
ts->wpaint = MEM_dupallocN(ts->wpaint);
ts->wpaint->paintcursor = NULL;
ts->wpaint->vpaint_prev = NULL;
ts->wpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag_subdata);
}
if (ts->sculpt) {
ts->sculpt = MEM_dupallocN(ts->sculpt);
BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, flag_subdata);
}
if (ts->uvsculpt) {
ts->uvsculpt = MEM_dupallocN(ts->uvsculpt);
BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, flag_subdata);
}
BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, flag_subdata);
ts->imapaint.paintcursor = NULL;
ts->particle.paintcursor = NULL;
ts->particle.scene = NULL;
ts->particle.object = NULL;
/* duplicate Grease Pencil Drawing Brushes */
BLI_listbase_clear(&ts->gp_brushes);
for (bGPDbrush *brush = sce_src->toolsettings->gp_brushes.first; brush; brush = brush->next) {
bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush);
BLI_addtail(&ts->gp_brushes, newbrush);
}
/* duplicate Grease Pencil interpolation curve */
ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo);
}
/* make a private copy of the avicodecdata */
if (sce_src->r.avicodecdata) {
sce_dst->r.avicodecdata = MEM_dupallocN(sce_src->r.avicodecdata);
sce_dst->r.avicodecdata->lpFormat = MEM_dupallocN(sce_dst->r.avicodecdata->lpFormat);
sce_dst->r.avicodecdata->lpParms = MEM_dupallocN(sce_dst->r.avicodecdata->lpParms);
}
/* make a private copy of the qtcodecdata */
if (sce_src->r.qtcodecdata) {
sce_dst->r.qtcodecdata = MEM_dupallocN(sce_src->r.qtcodecdata);
sce_dst->r.qtcodecdata->cdParms = MEM_dupallocN(sce_dst->r.qtcodecdata->cdParms);
}
if (sce_src->r.ffcodecdata.properties) { /* intentionally check sce_dst not sce_src. */ /* XXX ??? comment outdated... */
sce_dst->r.ffcodecdata.properties = IDP_CopyProperty_ex(sce_src->r.ffcodecdata.properties, flag_subdata);
}
/* before scene copy */
BKE_sound_create_scene(sce_dst);
/* Copy sequencer, this is local data! */
if (sce_src->ed) {
sce_dst->ed = MEM_callocN(sizeof(*sce_dst->ed), __func__);
sce_dst->ed->seqbasep = &sce_dst->ed->seqbase;
BKE_sequence_base_dupli_recursive(
sce_src, sce_dst, &sce_dst->ed->seqbase, &sce_src->ed->seqbase, SEQ_DUPE_ALL, flag_subdata);
}
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&sce_dst->id, &sce_src->id);
}
else {
sce_dst->preview = NULL;
}
}
Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
{
Scene *sce_copy;
/* TODO this should/could most likely be replaced by call to more generic code at some point...
* But for now, let's keep it well isolated here. */
if (type == SCE_COPY_EMPTY) {
ToolSettings *ts;
ListBase rl, rv;
sce_copy = BKE_scene_add(bmain, sce->id.name + 2);
rl = sce_copy->r.layers;
rv = sce_copy->r.views;
curvemapping_free_data(&sce_copy->r.mblur_shutter_curve);
sce_copy->r = sce->r;
sce_copy->r.layers = rl;
sce_copy->r.actlay = 0;
sce_copy->r.views = rv;
sce_copy->unit = sce->unit;
sce_copy->physics_settings = sce->physics_settings;
sce_copy->gm = sce->gm;
sce_copy->audio = sce->audio;
if (sce->id.properties)
sce_copy->id.properties = IDP_CopyProperty(sce->id.properties);
MEM_freeN(sce_copy->toolsettings);
BKE_sound_destroy_scene(sce_copy);
/* copy color management settings */
BKE_color_managed_display_settings_copy(&sce_copy->display_settings, &sce->display_settings);
BKE_color_managed_view_settings_copy(&sce_copy->view_settings, &sce->view_settings);
BKE_color_managed_colorspace_settings_copy(&sce_copy->sequencer_colorspace_settings, &sce->sequencer_colorspace_settings);
BKE_color_managed_display_settings_copy(&sce_copy->r.im_format.display_settings, &sce->r.im_format.display_settings);
BKE_color_managed_view_settings_copy(&sce_copy->r.im_format.view_settings, &sce->r.im_format.view_settings);
BKE_color_managed_display_settings_copy(&sce_copy->r.bake.im_format.display_settings, &sce->r.bake.im_format.display_settings);
BKE_color_managed_view_settings_copy(&sce_copy->r.bake.im_format.view_settings, &sce->r.bake.im_format.view_settings);
curvemapping_copy_data(&sce_copy->r.mblur_shutter_curve, &sce->r.mblur_shutter_curve);
/* tool settings */
sce_copy->toolsettings = MEM_dupallocN(sce->toolsettings);
ts = sce_copy->toolsettings;
if (ts) {
if (ts->vpaint) {
ts->vpaint = MEM_dupallocN(ts->vpaint);
ts->vpaint->paintcursor = NULL;
ts->vpaint->vpaint_prev = NULL;
ts->vpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, 0);
}
if (ts->wpaint) {
ts->wpaint = MEM_dupallocN(ts->wpaint);
ts->wpaint->paintcursor = NULL;
ts->wpaint->vpaint_prev = NULL;
ts->wpaint->wpaint_prev = NULL;
BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, 0);
}
if (ts->sculpt) {
ts->sculpt = MEM_dupallocN(ts->sculpt);
BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, 0);
}
if (ts->uvsculpt) {
ts->uvsculpt = MEM_dupallocN(ts->uvsculpt);
BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, 0);
}
BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, 0);
ts->imapaint.paintcursor = NULL;
id_us_plus((ID *)ts->imapaint.stencil);
id_us_plus((ID *)ts->imapaint.clone);
id_us_plus((ID *)ts->imapaint.canvas);
ts->particle.paintcursor = NULL;
ts->particle.scene = NULL;
ts->particle.object = NULL;
/* duplicate Grease Pencil Drawing Brushes */
BLI_listbase_clear(&ts->gp_brushes);
for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) {
bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush);
BLI_addtail(&ts->gp_brushes, newbrush);
}
/* duplicate Grease Pencil interpolation curve */
ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo);
}
/* make a private copy of the avicodecdata */
if (sce->r.avicodecdata) {
sce_copy->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
sce_copy->r.avicodecdata->lpFormat = MEM_dupallocN(sce_copy->r.avicodecdata->lpFormat);
sce_copy->r.avicodecdata->lpParms = MEM_dupallocN(sce_copy->r.avicodecdata->lpParms);
}
/* make a private copy of the qtcodecdata */
if (sce->r.qtcodecdata) {
sce_copy->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
sce_copy->r.qtcodecdata->cdParms = MEM_dupallocN(sce_copy->r.qtcodecdata->cdParms);
}
if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
sce_copy->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
}
/* before scene copy */
BKE_sound_create_scene(sce_copy);
/* grease pencil */
sce_copy->gpd = NULL;
sce_copy->preview = NULL;
return sce_copy;
}
else {
BKE_id_copy_ex(bmain, (ID *)sce, (ID **)&sce_copy, LIB_ID_COPY_ACTIONS, false);
/* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks... */
if (type == SCE_COPY_FULL) {
/* Copy Freestyle LineStyle datablocks. */
for (SceneRenderLayer *srl_dst = sce_copy->r.layers.first; srl_dst; srl_dst = srl_dst->next) {
for (FreestyleLineSet *lineset = srl_dst->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
if (lineset->linestyle) {
/* XXX Not copying anim/actions here? */
BKE_id_copy_ex(bmain, (ID *)lineset->linestyle, (ID **)&lineset->linestyle, 0, false);
}
}
}
/* Full copy of world (included animations) */
if (sce_copy->world) {
BKE_id_copy_ex(bmain, (ID *)sce_copy->world, (ID **)&sce_copy->world, LIB_ID_COPY_ACTIONS, false);
}
/* Full copy of GreasePencil. */
/* XXX Not copying anim/actions here? */
if (sce_copy->gpd) {
BKE_id_copy_ex(bmain, (ID *)sce_copy->gpd, (ID **)&sce_copy->gpd, 0, false);
}
}
else {
/* Remove sequencer if not full copy */
/* XXX Why in Hell? :/ */
remove_sequencer_fcurves(sce_copy);
BKE_sequencer_editing_free(sce_copy);
}
/* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
* are done outside of blenkernel with ED_objects_single_users! */
/* camera */
if (ELEM(type, SCE_COPY_LINK_DATA, SCE_COPY_FULL)) {
ID_NEW_REMAP(sce_copy->camera);
}
return sce_copy;
}
}
void BKE_scene_groups_relink(Scene *sce)
{
if (sce->rigidbody_world)
BKE_rigidbody_world_groups_relink(sce->rigidbody_world);
}
void BKE_scene_make_local(Main *bmain, Scene *sce, const bool lib_local)
{
/* For now should work, may need more work though to support all possible corner cases
* (also scene_copy probably needs some love). */
BKE_id_make_local_generic(bmain, &sce->id, true, lib_local);
}
/** Free (or release) any data used by this scene (does not free the scene itself). */
void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
{
SceneRenderLayer *srl;
BKE_animdata_free((ID *)sce, false);
/* check all sequences */
BKE_sequencer_clear_scene_in_allseqs(G.main, sce);
sce->basact = NULL;
BLI_freelistN(&sce->base);
BKE_sequencer_editing_free(sce);
BKE_keyingsets_free(&sce->keyingsets);
/* is no lib link block, but scene extension */
if (sce->nodetree) {
ntreeFreeTree(sce->nodetree);
MEM_freeN(sce->nodetree);
sce->nodetree = NULL;
}
if (sce->rigidbody_world) {
BKE_rigidbody_free_world(sce->rigidbody_world);
sce->rigidbody_world = NULL;
}
if (sce->r.avicodecdata) {
free_avicodecdata(sce->r.avicodecdata);
MEM_freeN(sce->r.avicodecdata);
sce->r.avicodecdata = NULL;
}
if (sce->r.qtcodecdata) {
free_qtcodecdata(sce->r.qtcodecdata);
MEM_freeN(sce->r.qtcodecdata);
sce->r.qtcodecdata = NULL;
}
if (sce->r.ffcodecdata.properties) {
IDP_FreeProperty(sce->r.ffcodecdata.properties);
MEM_freeN(sce->r.ffcodecdata.properties);
sce->r.ffcodecdata.properties = NULL;
}
for (srl = sce->r.layers.first; srl; srl = srl->next) {
if (srl->prop != NULL) {
IDP_FreeProperty(srl->prop);
MEM_freeN(srl->prop);
}
BKE_freestyle_config_free(&srl->freestyleConfig);
}
BLI_freelistN(&sce->markers);
BLI_freelistN(&sce->r.layers);
BLI_freelistN(&sce->r.views);
if (sce->toolsettings) {
if (sce->toolsettings->vpaint) {
BKE_paint_free(&sce->toolsettings->vpaint->paint);
MEM_freeN(sce->toolsettings->vpaint);
}
if (sce->toolsettings->wpaint) {
BKE_paint_free(&sce->toolsettings->wpaint->paint);
MEM_freeN(sce->toolsettings->wpaint);
}
if (sce->toolsettings->sculpt) {
BKE_paint_free(&sce->toolsettings->sculpt->paint);
MEM_freeN(sce->toolsettings->sculpt);
}
if (sce->toolsettings->uvsculpt) {
BKE_paint_free(&sce->toolsettings->uvsculpt->paint);
MEM_freeN(sce->toolsettings->uvsculpt);
}
BKE_paint_free(&sce->toolsettings->imapaint.paint);
/* free Grease Pencil Drawing Brushes */
BKE_gpencil_free_brushes(&sce->toolsettings->gp_brushes);
BLI_freelistN(&sce->toolsettings->gp_brushes);
/* free Grease Pencil interpolation curve */
if (sce->toolsettings->gp_interpolate.custom_ipo) {
curvemapping_free(sce->toolsettings->gp_interpolate.custom_ipo);
}
MEM_freeN(sce->toolsettings);
sce->toolsettings = NULL;
}
DEG_scene_graph_free(sce);
if (sce->depsgraph_legacy)
DEG_graph_free(sce->depsgraph_legacy);
MEM_SAFE_FREE(sce->fps_info);
BKE_sound_destroy_scene(sce);
BKE_color_managed_view_settings_free(&sce->view_settings);
BKE_previewimg_free(&sce->preview);
curvemapping_free_data(&sce->r.mblur_shutter_curve);
for (SceneLayer *sl = sce->render_layers.first, *sl_next; sl; sl = sl_next) {
sl_next = sl->next;
BLI_remlink(&sce->render_layers, sl);
BKE_scene_layer_free(sl);
}
/* Master Collection */
BKE_collection_master_free(sce, do_id_user);
MEM_freeN(sce->collection);
sce->collection = NULL;
/* LayerCollection engine settings. */
if (sce->collection_properties) {
IDP_FreeProperty(sce->collection_properties);
MEM_freeN(sce->collection_properties);
sce->collection_properties = NULL;
}
/* Render engine setting. */
if (sce->layer_properties) {
IDP_FreeProperty(sce->layer_properties);
MEM_freeN(sce->layer_properties);
sce->layer_properties = NULL;
}
}
void BKE_scene_free(Scene *sce)
{
BKE_scene_free_ex(sce, true);
}
void BKE_scene_init(Scene *sce)
{
ParticleEditSettings *pset;
int a;
const char *colorspace_name;
SceneRenderView *srv;
CurveMapping *mblur_shutter_curve;
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(sce, id));
sce->lay = sce->layact = 1;
sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE;
sce->r.cfra = 1;
sce->r.sfra = 1;
sce->r.efra = 250;
sce->r.frame_step = 1;
sce->r.xsch = 1920;
sce->r.ysch = 1080;
sce->r.xasp = 1;
sce->r.yasp = 1;
sce->r.tilex = 256;
sce->r.tiley = 256;
sce->r.mblur_samples = 1;
sce->r.filtertype = R_FILTER_MITCH;
sce->r.size = 50;
sce->r.im_format.planes = R_IMF_PLANES_RGBA;
sce->r.im_format.imtype = R_IMF_IMTYPE_PNG;
sce->r.im_format.depth = R_IMF_CHAN_DEPTH_8;
sce->r.im_format.quality = 90;
sce->r.im_format.compress = 15;
sce->r.displaymode = R_OUTPUT_AREA;
sce->r.framapto = 100;
sce->r.images = 100;
sce->r.framelen = 1.0;
sce->r.blurfac = 0.5;
sce->r.frs_sec = 24;
sce->r.frs_sec_base = 1;
sce->r.edgeint = 10;
sce->r.ocres = 128;
/* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used,
* images would look in the same way as in current blender
*
* perhaps at some point should be completely deprecated?
*/
sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
sce->r.gauss = 1.0;
/* deprecated but keep for upwards compat */
sce->r.postgamma = 1.0;
sce->r.posthue = 0.0;
sce->r.postsat = 1.0;
sce->r.bake_mode = 1; /* prevent to include render stuff here */
sce->r.bake_filter = 16;
sce->r.bake_osa = 5;
sce->r.bake_flag = R_BAKE_CLEAR;
sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT;
sce->r.bake_samples = 256;
sce->r.bake_biasdist = 0.001;
sce->r.bake.flag = R_BAKE_CLEAR;
sce->r.bake.pass_filter = R_BAKE_PASS_FILTER_ALL;
sce->r.bake.width = 512;
sce->r.bake.height = 512;
sce->r.bake.margin = 16;
sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
sce->r.bake.im_format.quality = 90;
sce->r.bake.im_format.compress = 15;
sce->r.scemode = R_DOCOMP | R_DOSEQ | R_EXTENSION;
sce->r.stamp = R_STAMP_TIME | R_STAMP_FRAME | R_STAMP_DATE | R_STAMP_CAMERA | R_STAMP_SCENE | R_STAMP_FILENAME | R_STAMP_RENDERTIME | R_STAMP_MEMORY;
sce->r.stamp_font_id = 12;
sce->r.fg_stamp[0] = sce->r.fg_stamp[1] = sce->r.fg_stamp[2] = 0.8f;
sce->r.fg_stamp[3] = 1.0f;
sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f;
sce->r.bg_stamp[3] = 0.25f;
sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES;
sce->r.seq_prev_type = OB_SOLID;
sce->r.seq_rend_type = OB_SOLID;
sce->r.seq_flag = 0;
sce->r.threads = 1;
sce->r.simplify_subsurf = 6;
sce->r.simplify_particles = 1.0f;
sce->r.simplify_shadowsamples = 16;
sce->r.simplify_aosss = 1.0f;
sce->r.border.xmin = 0.0f;
sce->r.border.ymin = 0.0f;
sce->r.border.xmax = 1.0f;
sce->r.border.ymax = 1.0f;
sce->r.preview_start_resolution = 64;
sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE;
sce->r.unit_line_thickness = 1.0f;
mblur_shutter_curve = &sce->r.mblur_shutter_curve;
curvemapping_set_defaults(mblur_shutter_curve, 1, 0.0f, 0.0f, 1.0f, 1.0f);
curvemapping_initialize(mblur_shutter_curve);
curvemap_reset(mblur_shutter_curve->cm,
&mblur_shutter_curve->clipr,
CURVE_PRESET_MAX,
CURVEMAP_SLOPE_POS_NEG);
sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct");
sce->toolsettings->doublimit = 0.001;
sce->toolsettings->vgroup_weight = 1.0f;
sce->toolsettings->uvcalc_margin = 0.001f;
sce->toolsettings->unwrapper = 1;
sce->toolsettings->select_thresh = 0.01f;
sce->toolsettings->selectmode = SCE_SELECT_VERTEX;
sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX;
sce->toolsettings->normalsize = 0.1;
sce->toolsettings->autokey_mode = U.autokey_mode;
sce->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
sce->toolsettings->skgen_resolution = 100;
sce->toolsettings->skgen_threshold_internal = 0.01f;
sce->toolsettings->skgen_threshold_external = 0.01f;
sce->toolsettings->skgen_angle_limit = 45.0f;
sce->toolsettings->skgen_length_ratio = 1.3f;
sce->toolsettings->skgen_length_limit = 1.5f;
sce->toolsettings->skgen_correlation_limit = 0.98f;
sce->toolsettings->skgen_symmetry_limit = 0.1f;
sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
sce->toolsettings->skgen_postpro_passes = 1;
sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING;
sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
sce->toolsettings->curve_paint_settings.curve_type = CU_BEZIER;
sce->toolsettings->curve_paint_settings.flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
sce->toolsettings->curve_paint_settings.error_threshold = 8;
sce->toolsettings->curve_paint_settings.radius_max = 1.0f;
sce->toolsettings->curve_paint_settings.corner_angle = DEG2RADF(70.0f);
sce->toolsettings->statvis.overhang_axis = OB_NEGZ;
sce->toolsettings->statvis.overhang_min = 0;
sce->toolsettings->statvis.overhang_max = DEG2RADF(45.0f);
sce->toolsettings->statvis.thickness_max = 0.1f;
sce->toolsettings->statvis.thickness_samples = 1;
sce->toolsettings->statvis.distort_min = DEG2RADF(5.0f);
sce->toolsettings->statvis.distort_max = DEG2RADF(45.0f);
sce->toolsettings->statvis.sharp_min = DEG2RADF(90.0f);
sce->toolsettings->statvis.sharp_max = DEG2RADF(180.0f);
sce->toolsettings->proportional_size = 1.0f;
sce->toolsettings->imapaint.paint.flags |= PAINT_SHOW_BRUSH;
sce->toolsettings->imapaint.normal_angle = 80;
sce->toolsettings->imapaint.seam_bleed = 2;
sce->physics_settings.gravity[0] = 0.0f;
sce->physics_settings.gravity[1] = 0.0f;
sce->physics_settings.gravity[2] = -9.81f;
sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
sce->unit.scale_length = 1.0f;
pset = &sce->toolsettings->particle;
pset->flag = PE_KEEP_LENGTHS | PE_LOCK_FIRST | PE_DEFLECT_EMITTER | PE_AUTO_VELOCITY;
pset->emitterdist = 0.25f;
pset->totrekey = 5;
pset->totaddkey = 5;
pset->brushtype = PE_BRUSH_NONE;
pset->draw_step = 2;
pset->fade_frames = 2;
pset->selectmode = SCE_SELECT_PATH;
for (a = 0; a < PE_TOT_BRUSH; a++) {
pset->brush[a].strength = 0.5f;
pset->brush[a].size = 50;
pset->brush[a].step = 10;
pset->brush[a].count = 10;
}
pset->brush[PE_BRUSH_CUT].strength = 1.0f;
sce->r.ffcodecdata.audio_mixrate = 48000;
sce->r.ffcodecdata.audio_volume = 1.0f;
sce->r.ffcodecdata.audio_bitrate = 192;
sce->r.ffcodecdata.audio_channels = 2;
BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(sce->r.engine));
sce->audio.distance_model = 2.0f;
sce->audio.doppler_factor = 1.0f;
sce->audio.speed_of_sound = 343.3f;
sce->audio.volume = 1.0f;
BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic));
BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
sce->r.osa = 8;
/* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
BKE_scene_add_render_layer(sce, NULL);
/* multiview - stereo */
BKE_scene_add_render_view(sce, STEREO_LEFT_NAME);
srv = sce->r.views.first;
BLI_strncpy(srv->suffix, STEREO_LEFT_SUFFIX, sizeof(srv->suffix));
BKE_scene_add_render_view(sce, STEREO_RIGHT_NAME);
srv = sce->r.views.last;
BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
/* game data */
sce->gm.stereoflag = STEREO_NOSTEREO;
sce->gm.stereomode = STEREO_ANAGLYPH;
sce->gm.eyeseparation = 0.10;
sce->gm.dome.angle = 180;
sce->gm.dome.mode = DOME_FISHEYE;
sce->gm.dome.res = 4;
sce->gm.dome.resbuf = 1.0f;
sce->gm.dome.tilt = 0;
sce->gm.xplay = 640;
sce->gm.yplay = 480;
sce->gm.freqplay = 60;
sce->gm.depth = 32;
sce->gm.gravity = 9.8f;
sce->gm.physicsEngine = WOPHY_BULLET;
sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling
sce->gm.occlusionRes = 128;
sce->gm.ticrate = 60;
sce->gm.maxlogicstep = 5;
sce->gm.physubstep = 1;
sce->gm.maxphystep = 5;
sce->gm.lineardeactthreshold = 0.8f;
sce->gm.angulardeactthreshold = 1.0f;
sce->gm.deactivationtime = 0.0f;
sce->gm.flag = 0;
sce->gm.matmode = GAME_MAT_MULTITEX;
sce->gm.obstacleSimulation = OBSTSIMULATION_NONE;
sce->gm.levelHeight = 2.f;
sce->gm.recastData.cellsize = 0.3f;
sce->gm.recastData.cellheight = 0.2f;
sce->gm.recastData.agentmaxslope = M_PI_4;
sce->gm.recastData.agentmaxclimb = 0.9f;
sce->gm.recastData.agentheight = 2.0f;
sce->gm.recastData.agentradius = 0.6f;
sce->gm.recastData.edgemaxlen = 12.0f;
sce->gm.recastData.edgemaxerror = 1.3f;
sce->gm.recastData.regionminsize = 8.f;
sce->gm.recastData.regionmergesize = 20.f;
sce->gm.recastData.vertsperpoly = 6;
sce->gm.recastData.detailsampledist = 6.0f;
sce->gm.recastData.detailsamplemaxerror = 1.0f;
sce->gm.lodflag = SCE_LOD_USE_HYST;
sce->gm.scehysteresis = 10;
sce->gm.exitkey = 218; // Blender key code for ESC
BKE_sound_create_scene(sce);
/* color management */
colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_SEQUENCER);
BKE_color_managed_display_settings_init(&sce->display_settings);
BKE_color_managed_view_settings_init(&sce->view_settings);
BLI_strncpy(sce->sequencer_colorspace_settings.name, colorspace_name,
sizeof(sce->sequencer_colorspace_settings.name));
/* Safe Areas */
copy_v2_fl2(sce->safe_areas.title, 3.5f / 100.0f, 3.5f / 100.0f);
copy_v2_fl2(sce->safe_areas.action, 10.0f / 100.0f, 5.0f / 100.0f);
copy_v2_fl2(sce->safe_areas.title_center, 17.5f / 100.0f, 5.0f / 100.0f);
copy_v2_fl2(sce->safe_areas.action_center, 15.0f / 100.0f, 5.0f / 100.0f);
sce->preview = NULL;
/* GP Sculpt brushes */
{
GP_BrushEdit_Settings *gset = &sce->toolsettings->gp_sculpt;
GP_EditBrush_Data *gp_brush;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
gp_brush->size = 25;
gp_brush->strength = 0.3f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
gp_brush->size = 25;
gp_brush->strength = 0.5f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
gp_brush->size = 25;
gp_brush->strength = 0.5f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
gp_brush->size = 50;
gp_brush->strength = 0.3f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
gp_brush->size = 25;
gp_brush->strength = 0.3f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
gp_brush->size = 50;
gp_brush->strength = 0.3f; // XXX?
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
gp_brush->size = 50;
gp_brush->strength = 0.5f; // XXX?
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
gp_brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
gp_brush->size = 25;
gp_brush->strength = 0.5f;
gp_brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
}
/* GP Stroke Placement */
sce->toolsettings->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
/* Master Collection */
sce->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
BLI_strncpy(sce->collection->name, "Master Collection", sizeof(sce->collection->name));
/* Engine settings */
IDPropertyTemplate val = {0};
sce->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BKE_layer_collection_engine_settings_create(sce->collection_properties);
sce->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BKE_scene_layer_engine_settings_create(sce->layer_properties);
BKE_scene_layer_add(sce, "Render Layer");
}
Scene *BKE_scene_add(Main *bmain, const char *name)
{
Scene *sce;
sce = BKE_libblock_alloc(bmain, ID_SCE, name, 0);
id_us_min(&sce->id);
id_us_ensure_real(&sce->id);
BKE_scene_init(sce);
return sce;
}
BaseLegacy *BKE_scene_base_find_by_name(struct Scene *scene, const char *name)
{
BaseLegacy *base;
for (base = scene->base.first; base; base = base->next) {
if (STREQ(base->object->id.name + 2, name)) {
break;
}
}
return base;
}
BaseLegacy *BKE_scene_base_find(Scene *scene, Object *ob)
{
return BLI_findptr(&scene->base, ob, offsetof(BaseLegacy, object));
}
/**
* Sets the active scene, mainly used when running in background mode (``--scene`` command line argument).
* This is also called to set the scene directly, bypassing windowing code.
* Otherwise #WM_window_change_active_scene is used when changing scenes by the user.
*/
void BKE_scene_set_background(Main *bmain, Scene *scene)
{
Scene *sce;
BaseLegacy *base;
Object *ob;
Group *group;
GroupObject *go;
/* check for cyclic sets, for reading old files but also for definite security (py?) */
BKE_scene_validate_setscene(bmain, scene);
/* can happen when switching modes in other scenes */
if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT))
scene->obedit = NULL;
/* deselect objects (for dataselect) */
for (ob = bmain->object.first; ob; ob = ob->id.next)
ob->flag &= ~(SELECT | OB_FROMGROUP);
/* group flags again */
for (group = bmain->group.first; group; group = group->id.next) {
for (go = group->gobject.first; go; go = go->next) {
if (go->ob) {
go->ob->flag |= OB_FROMGROUP;
}
}
}
/* sort baselist for scene and sets */
for (sce = scene; sce; sce = sce->set)
DEG_scene_relations_rebuild(bmain, sce);
/* copy layers and flags from bases to objects */
for (base = scene->base.first; base; base = base->next) {
ob = base->object;
ob->lay = base->lay;
/* group patch... */
BKE_scene_base_flag_sync_from_base(base);
}
/* no full animation update, this to enable render code to work (render code calls own animation updates) */
}
/* called from creator_args.c */
Scene *BKE_scene_set_name(Main *bmain, const char *name)
{
Scene *sce = (Scene *)BKE_libblock_find_name_ex(bmain, ID_SCE, name);
if (sce) {
BKE_scene_set_background(bmain, sce);
printf("Scene switch for render: '%s' in file: '%s'\n", name, bmain->name);
return sce;
}
printf("Can't find scene: '%s' in file: '%s'\n", name, bmain->name);
return NULL;
}
/* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */
int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
Scene **scene, int val, BaseLegacy **base, Object **ob)
{
bool run_again = true;
/* init */
if (val == 0) {
iter->phase = F_START;
iter->dupob = NULL;
iter->duplilist = NULL;
iter->dupli_refob = NULL;
}
else {
/* run_again is set when a duplilist has been ended */
while (run_again) {
run_again = false;
/* the first base */
if (iter->phase == F_START) {
*base = (*scene)->base.first;
if (*base) {
*ob = (*base)->object;
iter->phase = F_SCENE;
}
else {
/* exception: empty scene */
while ((*scene)->set) {
(*scene) = (*scene)->set;
if ((*scene)->base.first) {
*base = (*scene)->base.first;
*ob = (*base)->object;
iter->phase = F_SCENE;
break;
}
}
}
}
else {
if (*base && iter->phase != F_DUPLI) {
*base = (*base)->next;
if (*base) {
*ob = (*base)->object;
}
else {
if (iter->phase == F_SCENE) {
/* (*scene) is finished, now do the set */
while ((*scene)->set) {
(*scene) = (*scene)->set;
if ((*scene)->base.first) {
*base = (*scene)->base.first;
*ob = (*base)->object;
break;
}
}
}
}
}
}
if (*base == NULL) {
iter->phase = F_START;
}
else {
if (iter->phase != F_DUPLI) {
if ( (*base)->object->transflag & OB_DUPLI) {
/* groups cannot be duplicated for mballs yet,
* this enters eternal loop because of
* makeDispListMBall getting called inside of group_duplilist */
if ((*base)->object->dup_group == NULL) {
iter->duplilist = object_duplilist_ex(eval_ctx, (*scene), (*base)->object, false);
iter->dupob = iter->duplilist->first;
if (!iter->dupob) {
free_object_duplilist(iter->duplilist);
iter->duplilist = NULL;
}
iter->dupli_refob = NULL;
}
}
}
/* handle dupli's */
if (iter->dupob) {
(*base)->flag_legacy |= OB_FROMDUPLI;
*ob = iter->dupob->ob;
iter->phase = F_DUPLI;
if (iter->dupli_refob != *ob) {
if (iter->dupli_refob) {
/* Restore previous object's real matrix. */
copy_m4_m4(iter->dupli_refob->obmat, iter->omat);
}
/* Backup new object's real matrix. */
iter->dupli_refob = *ob;
copy_m4_m4(iter->omat, iter->dupli_refob->obmat);
}
copy_m4_m4((*ob)->obmat, iter->dupob->mat);
iter->dupob = iter->dupob->next;
}
else if (iter->phase == F_DUPLI) {
iter->phase = F_SCENE;
(*base)->flag_legacy &= ~OB_FROMDUPLI;
if (iter->dupli_refob) {
/* Restore last object's real matrix. */
copy_m4_m4(iter->dupli_refob->obmat, iter->omat);
iter->dupli_refob = NULL;
}
free_object_duplilist(iter->duplilist);
iter->duplilist = NULL;
run_again = true;
}
}
}
}
#if 0
if (ob && *ob) {
printf("Scene: '%s', '%s'\n", (*scene)->id.name + 2, (*ob)->id.name + 2);
}
#endif
return iter->phase;
}
Scene *BKE_scene_find_from_collection(const Main *bmain, const SceneCollection *scene_collection)
{
for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
for (SceneLayer *layer = scene->render_layers.first; layer; layer = layer->next) {
if (BKE_scene_layer_has_collection(layer, scene_collection)) {
return scene;
}
}
}
return NULL;
}
Object *BKE_scene_camera_find(Scene *sc)
{
BaseLegacy *base;
for (base = sc->base.first; base; base = base->next)
if (base->object->type == OB_CAMERA)
return base->object;
return NULL;
}
#ifdef DURIAN_CAMERA_SWITCH
Object *BKE_scene_camera_switch_find(Scene *scene)
{
TimeMarker *m;
int cfra = scene->r.cfra;
int frame = -(MAXFRAME + 1);
int min_frame = MAXFRAME + 1;
Object *camera = NULL;
Object *first_camera = NULL;
for (m = scene->markers.first; m; m = m->next) {
if (m->camera && (m->camera->restrictflag & OB_RESTRICT_RENDER) == 0) {
if ((m->frame <= cfra) && (m->frame > frame)) {
camera = m->camera;
frame = m->frame;
if (frame == cfra)
break;
}
if (m->frame < min_frame) {
first_camera = m->camera;
min_frame = m->frame;
}
}
}
if (camera == NULL) {
/* If there's no marker to the left of current frame,
* use camera from left-most marker to solve all sort
* of Schrodinger uncertainties.
*/
return first_camera;
}
return camera;
}
#endif
int BKE_scene_camera_switch_update(Scene *scene)
{
#ifdef DURIAN_CAMERA_SWITCH
Object *camera = BKE_scene_camera_switch_find(scene);
if (camera) {
scene->camera = camera;
return 1;
}
#else
(void)scene;
#endif
return 0;
}
char *BKE_scene_find_marker_name(Scene *scene, int frame)
{
ListBase *markers = &scene->markers;
TimeMarker *m1, *m2;
/* search through markers for match */
for (m1 = markers->first, m2 = markers->last; m1 && m2; m1 = m1->next, m2 = m2->prev) {
if (m1->frame == frame)
return m1->name;
if (m1 == m2)
break;
if (m2->frame == frame)
return m2->name;
}
return NULL;
}
/* return the current marker for this frame,
* we can have more than 1 marker per frame, this just returns the first :/ */
char *BKE_scene_find_last_marker_name(Scene *scene, int frame)
{
TimeMarker *marker, *best_marker = NULL;
int best_frame = -MAXFRAME * 2;
for (marker = scene->markers.first; marker; marker = marker->next) {
if (marker->frame == frame) {
return marker->name;
}
if (marker->frame > best_frame && marker->frame < frame) {
best_marker = marker;
best_frame = marker->frame;
}
}
return best_marker ? best_marker->name : NULL;
}
void BKE_scene_remove_rigidbody_object(Scene *scene, Object *ob)
{
/* remove rigid body constraint from world before removing object */
if (ob->rigidbody_constraint)
BKE_rigidbody_remove_constraint(scene, ob);
/* remove rigid body object from world before removing object */
if (ob->rigidbody_object)
BKE_rigidbody_remove_object(scene, ob);
}
BaseLegacy *BKE_scene_base_add(Scene *sce, Object *ob)
{
BaseLegacy *b = MEM_callocN(sizeof(*b), __func__);
BLI_addhead(&sce->base, b);
b->object = ob;
b->flag_legacy = ob->flag;
b->lay = ob->lay;
return b;
}
void BKE_scene_base_unlink(Scene *sce, BaseLegacy *base)
{
BKE_scene_remove_rigidbody_object(sce, base->object);
BLI_remlink(&sce->base, base);
if (sce->basact == base)
sce->basact = NULL;
}
/* deprecated, use BKE_scene_layer_base_deselect_all */
void BKE_scene_base_deselect_all(Scene *sce)
{
BaseLegacy *b;
for (b = sce->base.first; b; b = b->next) {
b->flag_legacy &= ~SELECT;
int flag = b->object->flag & (OB_FROMGROUP);
b->object->flag = b->flag_legacy;
b->object->flag |= flag;
}
}
void BKE_scene_base_select(Scene *sce, BaseLegacy *selbase)
{
selbase->flag_legacy |= SELECT;
selbase->object->flag = selbase->flag_legacy;
sce->basact = selbase;
}
/* checks for cycle, returns 1 if it's all OK */
bool BKE_scene_validate_setscene(Main *bmain, Scene *sce)
{
Scene *sce_iter;
int a, totscene;
if (sce->set == NULL) return true;
totscene = BLI_listbase_count(&bmain->scene);
for (a = 0, sce_iter = sce; sce_iter->set; sce_iter = sce_iter->set, a++) {
/* more iterations than scenes means we have a cycle */
if (a > totscene) {
/* the tested scene gets zero'ed, that's typically current scene */
sce->set = NULL;
return false;
}
}
return true;
}
/* This function is needed to cope with fractional frames - including two Blender rendering features
* mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering.
*/
float BKE_scene_frame_get(const Scene *scene)
{
return BKE_scene_frame_get_from_ctime(scene, scene->r.cfra);
}
/* This function is used to obtain arbitrary fractional frames */
float BKE_scene_frame_get_from_ctime(const Scene *scene, const float frame)
{
float ctime = frame;
ctime += scene->r.subframe;
ctime *= scene->r.framelen;
return ctime;
}
/**
* Sets the frame int/float components.
*/
void BKE_scene_frame_set(struct Scene *scene, double cfra)
{
double intpart;
scene->r.subframe = modf(cfra, &intpart);
scene->r.cfra = (int)intpart;
}
/* That's like really a bummer, because currently animation data for armatures
* might want to use pose, and pose might be missing on the object.
* This happens when changing visible layers, which leads to situations when
* pose is missing or marked for recalc, animation will change it and then
* object update will restore the pose.
*
* This could be solved by the new dependency graph, but for until then we'll
* do an extra pass on the objects to ensure it's all fine.
*/
#define POSE_ANIMATION_WORKAROUND
#ifdef POSE_ANIMATION_WORKAROUND
static void scene_armature_depsgraph_workaround(Main *bmain)
{
Object *ob;
if (BLI_listbase_is_empty(&bmain->armature) || !DEG_id_type_tagged(bmain, ID_OB)) {
return;
}
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->type == OB_ARMATURE && ob->adt && ob->adt->recalc & ADT_RECALC_ANIM) {
if (ob->pose == NULL || (ob->pose->flag & POSE_RECALC)) {
BKE_pose_rebuild(ob, ob->data);
}
}
}
}
#endif
static bool check_rendered_viewport_visible(Main *bmain)
{
wmWindowManager *wm = bmain->wm.first;
wmWindow *window;
for (window = wm->windows.first; window != NULL; window = window->next) {
const bScreen *screen = BKE_workspace_active_screen_get(window->workspace_hook);
Scene *scene = window->scene;
ScrArea *area;
RenderEngineType *type = RE_engines_find(scene->r.engine);
if ((type->draw_engine != NULL) || (type->render_to_view == NULL)) {
continue;
}
const bool use_legacy = (type->flag & RE_USE_LEGACY_PIPELINE) != 0;
for (area = screen->areabase.first; area != NULL; area = area->next) {
View3D *v3d = area->spacedata.first;
if (area->spacetype != SPACE_VIEW3D) {
continue;
}
if (v3d->drawtype == OB_RENDER || !use_legacy) {
return true;
}
}
}
return false;
}
static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
{
/* This is needed to prepare mesh to be used by the render
* engine from the viewport rendering. We do loading here
* so all the objects which shares the same mesh datablock
* are nicely tagged for update and updated.
*
* This makes it so viewport render engine doesn't need to
* call loading of the edit data for the mesh objects.
*/
Object *obedit = scene->obedit;
if (obedit) {
Mesh *mesh = obedit->data;
if ((obedit->type == OB_MESH) &&
((obedit->id.tag & LIB_TAG_ID_RECALC_ALL) ||
(mesh->id.tag & LIB_TAG_ID_RECALC_ALL)))
{
if (check_rendered_viewport_visible(bmain)) {
BMesh *bm = mesh->edit_btmesh->bm;
BM_mesh_bm_to_me(bm, mesh, (&(struct BMeshToMeshParams){0}));
DEG_id_tag_update(&mesh->id, 0);
}
}
}
}
void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *scene)
{
Scene *sce_iter;
/* (re-)build dependency graph if needed */
for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set) {
DEG_scene_relations_update(bmain, sce_iter);
/* Uncomment this to check if graph was properly tagged for update. */
#if 0
DEG_scene_relations_validate(bmain, sce_iter);
#endif
}
/* flush editing data if needed */
prepare_mesh_for_viewport_render(bmain, scene);
/* flush recalc flags to dependencies */
DEG_ids_flush_tagged(bmain, scene);
/* removed calls to quick_cache, see pointcache.c */
/* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later
* when trying to find materials with drivers that need evaluating [#32017]
*/
BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
/* update all objects: drivers, matrices, displists, etc. flags set
* by depgraph or manual, no layer check here, gets correct flushed
*
* in the future this should handle updates for all datablocks, not
* only objects and scenes. - brecht */
DEG_evaluate_on_refresh(eval_ctx, scene->depsgraph_legacy, scene);
/* TODO(sergey): This is to beocme a node in new depsgraph. */
BKE_mask_update_scene(bmain, scene);
/* update sound system animation (TODO, move to depsgraph) */
BKE_sound_update_scene(bmain, scene);
/* extra call here to recalc scene animation (for sequencer) */
{
AnimData *adt = BKE_animdata_from_id(&scene->id);
float ctime = BKE_scene_frame_get(scene);
if (adt && (adt->recalc & ADT_RECALC_ANIM))
BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0);
}
/* Inform editors about possible changes. */
DEG_ids_check_recalc(bmain, scene, false);
/* clear recalc flags */
DEG_ids_clear_recalc(bmain);
}
/* applies changes right away, does all sets too */
void BKE_scene_update_for_newframe(EvaluationContext *eval_ctx, Main *bmain, Scene *sce)
{
float ctime = BKE_scene_frame_get(sce);
Scene *sce_iter;
DEG_editors_update_pre(bmain, sce, true);
/* keep this first */
BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
/* update animated image textures for particles, modifiers, gpu, etc,
* call this at the start so modifiers with textures don't lag 1 frame */
BKE_image_update_frame(bmain, sce->r.cfra);
BKE_sound_set_cfra(sce->r.cfra);
/* clear animation overrides */
/* XXX TODO... */
for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set)
DEG_scene_relations_update(bmain, sce_iter);
BKE_mask_evaluate_all_masks(bmain, ctime, true);
/* Update animated cache files for modifiers. */
BKE_cachefile_update_frame(bmain, sce, ctime, (((double)sce->r.frs_sec) / (double)sce->r.frs_sec_base));
#ifdef POSE_ANIMATION_WORKAROUND
scene_armature_depsgraph_workaround(bmain);
#endif
/* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later
* when trying to find materials with drivers that need evaluating [#32017]
*/
BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
/* BKE_object_handle_update() on all objects, groups and sets */
DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph_legacy, ctime);
/* update sound system animation (TODO, move to depsgraph) */
BKE_sound_update_scene(bmain, sce);
/* notify editors and python about recalc */
BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_POST);
/* Inform editors about possible changes. */
DEG_ids_check_recalc(bmain, sce, true);
/* clear recalc flags */
DEG_ids_clear_recalc(bmain);
}
/* return default layer, also used to patch old files */
SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name)
{
SceneRenderLayer *srl;
if (!name)
name = DATA_("RenderLayer");
srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
BLI_strncpy(srl->name, name, sizeof(srl->name));
BLI_uniquename(&sce->r.layers, srl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(srl->name));
BLI_addtail(&sce->r.layers, srl);
/* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
srl->lay = (1 << 20) - 1;
srl->layflag = 0x7FFF; /* solid ztra halo edge strand */
srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
srl->pass_alpha_threshold = 0.5f;
BKE_freestyle_config_init(&srl->freestyleConfig);
return srl;
}
bool BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl)
{
const int act = BLI_findindex(&scene->r.layers, srl);
Scene *sce;
if (act == -1) {
return false;
}
else if ( (scene->r.layers.first == scene->r.layers.last) &&
(scene->r.layers.first == srl))
{
/* ensure 1 layer is kept */
return false;
}
BKE_freestyle_config_free(&srl->freestyleConfig);
if (srl->prop) {
IDP_FreeProperty(srl->prop);
MEM_freeN(srl->prop);
}
BLI_remlink(&scene->r.layers, srl);
MEM_freeN(srl);
scene->r.actlay = 0;
for (sce = bmain->scene.first; sce; sce = sce->id.next) {
if (sce->nodetree) {
BKE_nodetree_remove_layer_n(sce->nodetree, scene, act);
}
}
return true;
}
/* return default view */
SceneRenderView *BKE_scene_add_render_view(Scene *sce, const char *name)
{
SceneRenderView *srv;
if (!name)
name = DATA_("RenderView");
srv = MEM_callocN(sizeof(SceneRenderView), "new render view");
BLI_strncpy(srv->name, name, sizeof(srv->name));
BLI_uniquename(&sce->r.views, srv, DATA_("RenderView"), '.', offsetof(SceneRenderView, name), sizeof(srv->name));
BLI_addtail(&sce->r.views, srv);
return srv;
}
bool BKE_scene_remove_render_view(Scene *scene, SceneRenderView *srv)
{
const int act = BLI_findindex(&scene->r.views, srv);
if (act == -1) {
return false;
}
else if (scene->r.views.first == scene->r.views.last) {
/* ensure 1 view is kept */
return false;
}
BLI_remlink(&scene->r.views, srv);
MEM_freeN(srv);
scene->r.actview = 0;
return true;
}
/* render simplification */
int get_render_subsurf_level(const RenderData *r, int lvl, bool for_render)
{
if (r->mode & R_SIMPLIFY) {
if (for_render)
return min_ii(r->simplify_subsurf_render, lvl);
else
return min_ii(r->simplify_subsurf, lvl);
}
else {
return lvl;
}
}
int get_render_child_particle_number(const RenderData *r, int num, bool for_render)
{
if (r->mode & R_SIMPLIFY) {
if (for_render)
return (int)(r->simplify_particles_render * num);
else
return (int)(r->simplify_particles * num);
}
else {
return num;
}
}
int get_render_shadow_samples(const RenderData *r, int samples)
{
if ((r->mode & R_SIMPLIFY) && samples > 0)
return min_ii(r->simplify_shadowsamples, samples);
else
return samples;
}
float get_render_aosss_error(const RenderData *r, float error)
{
if (r->mode & R_SIMPLIFY)
return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error;
else
return error;
}
/**
* Helper function for the SETLOOPER macro
*
* It iterates over the bases of the active layer and then the bases
* of the active layer of the background (set) scenes recursively.
*/
Base *_setlooper_base_step(Scene **sce_iter, Base *base)
{
if (base && base->next) {
/* common case, step to the next */
return base->next;
}
else if (base == NULL) {
/* first time looping, return the scenes first base */
/* for the first loop we should get the layer from context */
SceneLayer *sl = BKE_scene_layer_context_active_PLACEHOLDER((*sce_iter));
/* TODO For first scene (non-background set), we should pass the render layer as argument.
* In some cases we want it to be the workspace one, in other the scene one. */
TODO_LAYER;
if (sl->object_bases.first) {
return (Base *)sl->object_bases.first;
}
/* no base on this scene layer */
goto next_set;
}
else {
next_set:
/* reached the end, get the next base in the set */
while ((*sce_iter = (*sce_iter)->set)) {
SceneLayer *sl = BKE_scene_layer_from_scene_get((*sce_iter));
base = (Base *)sl->object_bases.first;
if (base) {
return base;
}
}
}
return NULL;
}
bool BKE_scene_use_new_shading_nodes(const Scene *scene)
{
const RenderEngineType *type = RE_engines_find(scene->r.engine);
return (type && type->flag & RE_USE_SHADING_NODES);
}
bool BKE_scene_use_shading_nodes_custom(Scene *scene)
{
RenderEngineType *type = RE_engines_find(scene->r.engine);
return (type && type->flag & RE_USE_SHADING_NODES_CUSTOM);
}
bool BKE_scene_use_world_space_shading(Scene *scene)
{
const RenderEngineType *type = RE_engines_find(scene->r.engine);
return ((scene->r.mode & R_USE_WS_SHADING) ||
(type && (type->flag & RE_USE_SHADING_NODES)));
}
bool BKE_scene_use_spherical_stereo(Scene *scene)
{
RenderEngineType *type = RE_engines_find(scene->r.engine);
return (type && type->flag & RE_USE_SPHERICAL_STEREO);
}
bool BKE_scene_uses_blender_internal(const Scene *scene)
{
return STREQ(scene->r.engine, RE_engine_id_BLENDER_RENDER);
}
bool BKE_scene_uses_blender_game(const Scene *scene)
{
return STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME);
}
bool BKE_scene_uses_blender_eevee(const Scene *scene)
{
return STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE);
}
void BKE_scene_base_flag_to_objects(SceneLayer *sl)
{
Base *base = sl->object_bases.first;
while (base) {
BKE_scene_object_base_flag_sync_from_base(base);
base = base->next;
}
}
void BKE_scene_base_flag_sync_from_base(BaseLegacy *base)
{
BKE_scene_object_base_flag_sync_from_base(base);
}
void BKE_scene_base_flag_sync_from_object(BaseLegacy *base)
{
BKE_scene_object_base_flag_sync_from_object(base);
}
void BKE_scene_object_base_flag_sync_from_base(Base *base)
{
Object *ob = base->object;
/* keep the object only flags untouched */
int flag = ob->flag & OB_FROMGROUP;
ob->flag = base->flag;
ob->flag |= flag;
if ((base->flag & BASE_SELECTED) != 0) {
ob->flag |= SELECT;
}
else {
ob->flag &= ~SELECT;
}
}
void BKE_scene_object_base_flag_sync_from_object(Base *base)
{
Object *ob = base->object;
base->flag = ob->flag;
if ((ob->flag & SELECT) != 0) {
base->flag |= BASE_SELECTED;
BLI_assert((base->flag & BASE_SELECTABLED) != 0);
}
else {
base->flag &= ~BASE_SELECTED;
}
}
void BKE_scene_disable_color_management(Scene *scene)
{
ColorManagedDisplaySettings *display_settings = &scene->display_settings;
ColorManagedViewSettings *view_settings = &scene->view_settings;
const char *view;
const char *none_display_name;
none_display_name = IMB_colormanagement_display_get_none_name();
BLI_strncpy(display_settings->display_device, none_display_name, sizeof(display_settings->display_device));
view = IMB_colormanagement_view_get_default_name(display_settings->display_device);
if (view) {
BLI_strncpy(view_settings->view_transform, view, sizeof(view_settings->view_transform));
}
}
bool BKE_scene_check_color_management_enabled(const Scene *scene)
{
return !STREQ(scene->display_settings.display_device, "None");
}
bool BKE_scene_check_rigidbody_active(const Scene *scene)
{
return scene && scene->rigidbody_world && scene->rigidbody_world->group && !(scene->rigidbody_world->flag & RBW_FLAG_MUTED);
}
int BKE_render_num_threads(const RenderData *rd)
{
int threads;
/* override set from command line? */
threads = BLI_system_num_threads_override_get();
if (threads > 0)
return threads;
/* fixed number of threads specified in scene? */
if (rd->mode & R_FIXED_THREADS)
threads = rd->threads;
else
threads = BLI_system_thread_count();
return max_ii(threads, 1);
}
int BKE_scene_num_threads(const Scene *scene)
{
return BKE_render_num_threads(&scene->r);
}
int BKE_render_preview_pixel_size(const RenderData *r)
{
if (r->preview_pixel_size == 0) {
return (U.pixelsize > 1.5f)? 2 : 1;
}
return r->preview_pixel_size;
}
/* Apply the needed correction factor to value, based on unit_type (only length-related are affected currently)
* and unit->scale_length.
*/
double BKE_scene_unit_scale(const UnitSettings *unit, const int unit_type, double value)
{
if (unit->system == USER_UNIT_NONE) {
/* Never apply scale_length when not using a unit setting! */
return value;
}
switch (unit_type) {
case B_UNIT_LENGTH:
return value * (double)unit->scale_length;
case B_UNIT_AREA:
return value * pow(unit->scale_length, 2);
case B_UNIT_VOLUME:
return value * pow(unit->scale_length, 3);
case B_UNIT_MASS:
return value * pow(unit->scale_length, 3);
case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See T42026. */
default:
return value;
}
}
/******************** multiview *************************/
int BKE_scene_multiview_num_views_get(const RenderData *rd)
{
SceneRenderView *srv;
int totviews = 0;
if ((rd->scemode & R_MULTIVIEW) == 0)
return 1;
if (rd->views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
srv = BLI_findstring(&rd->views, STEREO_LEFT_NAME, offsetof(SceneRenderView, name));
if ((srv && srv->viewflag & SCE_VIEW_DISABLE) == 0) {
totviews++;
}
srv = BLI_findstring(&rd->views, STEREO_RIGHT_NAME, offsetof(SceneRenderView, name));
if ((srv && srv->viewflag & SCE_VIEW_DISABLE) == 0) {
totviews++;
}
}
else {
for (srv = rd->views.first; srv; srv = srv->next) {
if ((srv->viewflag & SCE_VIEW_DISABLE) == 0) {
totviews++;
}
}
}
return totviews;
}
bool BKE_scene_multiview_is_stereo3d(const RenderData *rd)
{
SceneRenderView *srv[2];
if ((rd->scemode & R_MULTIVIEW) == 0)
return false;
srv[0] = (SceneRenderView *)BLI_findstring(&rd->views, STEREO_LEFT_NAME, offsetof(SceneRenderView, name));
srv[1] = (SceneRenderView *)BLI_findstring(&rd->views, STEREO_RIGHT_NAME, offsetof(SceneRenderView, name));
return (srv[0] && ((srv[0]->viewflag & SCE_VIEW_DISABLE) == 0) &&
srv[1] && ((srv[1]->viewflag & SCE_VIEW_DISABLE) == 0));
}
/* return whether to render this SceneRenderView */
bool BKE_scene_multiview_is_render_view_active(const RenderData *rd, const SceneRenderView *srv)
{
if (srv == NULL)
return false;
if ((rd->scemode & R_MULTIVIEW) == 0)
return false;
if ((srv->viewflag & SCE_VIEW_DISABLE))
return false;
if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW)
return true;
/* SCE_VIEWS_SETUP_BASIC */
if (STREQ(srv->name, STEREO_LEFT_NAME) ||
STREQ(srv->name, STEREO_RIGHT_NAME))
{
return true;
}
return false;
}
/* return true if viewname is the first or if the name is NULL or not found */
bool BKE_scene_multiview_is_render_view_first(const RenderData *rd, const char *viewname)
{
SceneRenderView *srv;
if ((rd->scemode & R_MULTIVIEW) == 0)
return true;
if ((!viewname) || (!viewname[0]))
return true;
for (srv = rd->views.first; srv; srv = srv->next) {
if (BKE_scene_multiview_is_render_view_active(rd, srv)) {
return STREQ(viewname, srv->name);
}
}
return true;
}
/* return true if viewname is the last or if the name is NULL or not found */
bool BKE_scene_multiview_is_render_view_last(const RenderData *rd, const char *viewname)
{
SceneRenderView *srv;
if ((rd->scemode & R_MULTIVIEW) == 0)
return true;
if ((!viewname) || (!viewname[0]))
return true;
for (srv = rd->views.last; srv; srv = srv->prev) {
if (BKE_scene_multiview_is_render_view_active(rd, srv)) {
return STREQ(viewname, srv->name);
}
}
return true;
}
SceneRenderView *BKE_scene_multiview_render_view_findindex(const RenderData *rd, const int view_id)
{
SceneRenderView *srv;
size_t nr;
if ((rd->scemode & R_MULTIVIEW) == 0)
return NULL;
for (srv = rd->views.first, nr = 0; srv; srv = srv->next) {
if (BKE_scene_multiview_is_render_view_active(rd, srv)) {
if (nr++ == view_id)
return srv;
}
}
return srv;
}
const char *BKE_scene_multiview_render_view_name_get(const RenderData *rd, const int view_id)
{
SceneRenderView *srv = BKE_scene_multiview_render_view_findindex(rd, view_id);
if (srv)
return srv->name;
else
return "";
}
int BKE_scene_multiview_view_id_get(const RenderData *rd, const char *viewname)
{
SceneRenderView *srv;
size_t nr;
if ((!rd) || ((rd->scemode & R_MULTIVIEW) == 0))
return 0;
if ((!viewname) || (!viewname[0]))
return 0;
for (srv = rd->views.first, nr = 0; srv; srv = srv->next) {
if (BKE_scene_multiview_is_render_view_active(rd, srv)) {
if (STREQ(viewname, srv->name)) {
return nr;
}
else {
nr += 1;
}
}
}
return 0;
}
void BKE_scene_multiview_filepath_get(
SceneRenderView *srv, const char *filepath,
char *r_filepath)
{
BLI_strncpy(r_filepath, filepath, FILE_MAX);
BLI_path_suffix(r_filepath, FILE_MAX, srv->suffix, "");
}
/**
* When multiview is not used the filepath is as usual (e.g., ``Image.jpg``).
* When multiview is on, even if only one view is enabled the view is incorporated
* into the file name (e.g., ``Image_L.jpg``). That allows for the user to re-render
* individual views.
*/
void BKE_scene_multiview_view_filepath_get(
const RenderData *rd, const char *filepath, const char *viewname,
char *r_filepath)
{
SceneRenderView *srv;
char suffix[FILE_MAX];
srv = BLI_findstring(&rd->views, viewname, offsetof(SceneRenderView, name));
if (srv)
BLI_strncpy(suffix, srv->suffix, sizeof(suffix));
else
BLI_strncpy(suffix, viewname, sizeof(suffix));
BLI_strncpy(r_filepath, filepath, FILE_MAX);
BLI_path_suffix(r_filepath, FILE_MAX, suffix, "");
}
const char *BKE_scene_multiview_view_suffix_get(const RenderData *rd, const char *viewname)
{
SceneRenderView *srv;
if ((viewname == NULL) || (viewname[0] == '\0'))
return viewname;
srv = BLI_findstring(&rd->views, viewname, offsetof(SceneRenderView, name));
if (srv)
return srv->suffix;
else
return viewname;
}
const char *BKE_scene_multiview_view_id_suffix_get(const RenderData *rd, const int view_id)
{
if ((rd->scemode & R_MULTIVIEW) == 0) {
return "";
}
else {
const char *viewname = BKE_scene_multiview_render_view_name_get(rd, view_id);
return BKE_scene_multiview_view_suffix_get(rd, viewname);
}
}
void BKE_scene_multiview_view_prefix_get(Scene *scene, const char *name, char *rprefix, const char **rext)
{
SceneRenderView *srv;
size_t index_act;
const char *suf_act;
const char delims[] = {'.', '\0'};
rprefix[0] = '\0';
/* begin of extension */
index_act = BLI_str_rpartition(name, delims, rext, &suf_act);
if (*rext == NULL)
return;
BLI_assert(index_act > 0);
UNUSED_VARS_NDEBUG(index_act);
for (srv = scene->r.views.first; srv; srv = srv->next) {
if (BKE_scene_multiview_is_render_view_active(&scene->r, srv)) {
size_t len = strlen(srv->suffix);
if (strlen(*rext) >= len && STREQLEN(*rext - len, srv->suffix, len)) {
BLI_strncpy(rprefix, name, strlen(name) - strlen(*rext) - len + 1);
break;
}
}
}
}
void BKE_scene_multiview_videos_dimensions_get(
const RenderData *rd, const size_t width, const size_t height,
size_t *r_width, size_t *r_height)
{
if ((rd->scemode & R_MULTIVIEW) &&
rd->im_format.views_format == R_IMF_VIEWS_STEREO_3D)
{
IMB_stereo3d_write_dimensions(
rd->im_format.stereo3d_format.display_mode,
(rd->im_format.stereo3d_format.flag & S3D_SQUEEZED_FRAME) != 0,
width, height,
r_width, r_height);
}
else {
*r_width = width;
*r_height = height;
}
}
int BKE_scene_multiview_num_videos_get(const RenderData *rd)
{
if (BKE_imtype_is_movie(rd->im_format.imtype) == false)
return 0;
if ((rd->scemode & R_MULTIVIEW) == 0)
return 1;
if (rd->im_format.views_format == R_IMF_VIEWS_STEREO_3D) {
return 1;
}
else {
/* R_IMF_VIEWS_INDIVIDUAL */
return BKE_scene_multiview_num_views_get(rd);
}
}
Depsgraph* BKE_scene_get_depsgraph(Scene *scene, SceneLayer *scene_layer)
{
(void) scene_layer;
return scene->depsgraph_legacy;
}
|