1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
|
/*
* 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) 2008 Blender Foundation, Joshua Leung
* All rights reserved.
*/
/** \file
* \ingroup edanimation
*/
/* This file contains a system used to provide a layer of abstraction between sources
* of animation data and tools in Animation Editors. The method used here involves
* generating a list of edit structures which enable tools to naively perform the actions
* they require without all the boiler-plate associated with loops within loops and checking
* for cases to ignore.
*
* While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
* the Graph Editor also uses this for its channel list and for determining which curves
* are being edited. Likewise, the NLA Editor also uses this for its channel list and in
* its operators.
*
* Note: much of the original system this was based on was built before the creation of the RNA
* system. In future, it would be interesting to replace some parts of this code with RNA queries,
* however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this
* system, so if any such work does occur, it should only be used for the internals used here...
*
* -- Joshua Leung, Dec 2008 (Last revision July 2009)
*/
#include <string.h>
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_brush_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_camera_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_hair_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_layer_types.h"
#include "DNA_light_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_mask_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_node_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_pointcloud_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_sequence_types.h"
#include "DNA_simulation_types.h"
#include "DNA_space_types.h"
#include "DNA_speaker_types.h"
#include "DNA_userdef_types.h"
#include "DNA_volume_types.h"
#include "DNA_world_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
#include "BKE_anim_data.h"
#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "BKE_fcurve_driver.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_mask.h"
#include "BKE_material.h"
#include "BKE_modifier.h"
#include "BKE_node.h"
#include "BKE_sequencer.h"
#include "ED_anim_api.h"
#include "ED_markers.h"
#include "UI_resources.h" /* for TH_KEYFRAME_SCALE lookup */
/* ************************************************************ */
/* Blender Context <-> Animation Context mapping */
/* ----------- Private Stuff - General -------------------- */
/* Get vertical scaling factor (i.e. typically used for keyframe size) */
static void animedit_get_yscale_factor(bAnimContext *ac)
{
bTheme *btheme = UI_GetTheme();
/* grab scale factor directly from action editor setting
* NOTE: This theme setting doesn't have an ID, as it cannot be accessed normally
* since it is a float, and the theme settings methods can only handle chars.
*/
ac->yscale_fac = btheme->space_action.keyframe_scale_fac;
/* clamp to avoid problems with uninitialized values... */
if (ac->yscale_fac < 0.1f) {
ac->yscale_fac = 1.0f;
}
// printf("yscale_fac = %f\n", ac->yscale_fac);
}
/* ----------- Private Stuff - Action Editor ------------- */
/* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
/* Note: there's a similar function in key.c (BKE_key_from_object) */
static Key *actedit_get_shapekeys(bAnimContext *ac)
{
ViewLayer *view_layer = ac->view_layer;
Object *ob;
Key *key;
ob = OBACT(view_layer);
if (ob == NULL) {
return NULL;
}
/* XXX pinning is not available in 'ShapeKey' mode... */
// if (saction->pin) return NULL;
/* shapekey data is stored with geometry data */
key = BKE_key_from_object(ob);
if (key) {
if (key->type == KEY_RELATIVE) {
return key;
}
}
return NULL;
}
/* Get data being edited in Action Editor (depending on current 'mode') */
static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
{
/* get dopesheet */
ac->ads = &saction->ads;
/* sync settings with current view status, then return appropriate data */
switch (saction->mode) {
case SACTCONT_ACTION: /* 'Action Editor' */
/* if not pinned, sync with active object */
if (/*saction->pin == 0*/ true) {
if (ac->obact && ac->obact->adt) {
saction->action = ac->obact->adt->action;
}
else {
saction->action = NULL;
}
}
ac->datatype = ANIMCONT_ACTION;
ac->data = saction->action;
ac->mode = saction->mode;
return true;
case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
ac->datatype = ANIMCONT_SHAPEKEY;
ac->data = actedit_get_shapekeys(ac);
/* if not pinned, sync with active object */
if (/*saction->pin == 0*/ true) {
Key *key = (Key *)ac->data;
if (key && key->adt) {
saction->action = key->adt->action;
}
else {
saction->action = NULL;
}
}
ac->mode = saction->mode;
return true;
case SACTCONT_GPENCIL: /* Grease Pencil */ /* XXX review how this mode is handled... */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
ac->datatype = ANIMCONT_GPENCIL;
ac->data = &saction->ads;
ac->mode = saction->mode;
return true;
case SACTCONT_CACHEFILE: /* Cache File */ /* XXX review how this mode is handled... */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
ac->datatype = ANIMCONT_CHANNEL;
ac->data = &saction->ads;
ac->mode = saction->mode;
return true;
case SACTCONT_MASK: /* Mask */ /* XXX review how this mode is handled... */
{
/* TODO, other methods to get the mask */
// Sequence *seq = BKE_sequencer_active_get(ac->scene);
// MovieClip *clip = ac->scene->clip;
// struct Mask *mask = seq ? seq->mask : NULL;
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
ac->datatype = ANIMCONT_MASK;
ac->data = &saction->ads;
ac->mode = saction->mode;
return true;
}
case SACTCONT_DOPESHEET: /* DopeSheet */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
ac->datatype = ANIMCONT_DOPESHEET;
ac->data = &saction->ads;
ac->mode = saction->mode;
return true;
case SACTCONT_TIMELINE: /* Timeline */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
/* sync scene's "selected keys only" flag with our "only selected" flag
*
* XXX: This is a workaround for T55525. We shouldn't really be syncing the flags like this,
* but it's a simpler fix for now than also figuring out how the next/prev keyframe
* tools should work in the 3D View if we allowed full access to the timeline's
* dopesheet filters (i.e. we'd have to figure out where to host those settings,
* to be on a scene level like this flag currently is, along with several other unknowns).
*/
if (ac->scene->flag & SCE_KEYS_NO_SELONLY) {
saction->ads.filterflag &= ~ADS_FILTER_ONLYSEL;
}
else {
saction->ads.filterflag |= ADS_FILTER_ONLYSEL;
}
ac->datatype = ANIMCONT_TIMELINE;
ac->data = &saction->ads;
ac->mode = saction->mode;
return true;
default: /* unhandled yet */
ac->datatype = ANIMCONT_NONE;
ac->data = NULL;
ac->mode = -1;
return false;
}
}
/* ----------- Private Stuff - Graph Editor ------------- */
/* Get data being edited in Graph Editor (depending on current 'mode') */
static bool graphedit_get_context(bAnimContext *ac, SpaceGraph *sipo)
{
/* init dopesheet data if non-existent (i.e. for old files) */
if (sipo->ads == NULL) {
sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
sipo->ads->source = (ID *)ac->scene;
}
ac->ads = sipo->ads;
/* set settings for Graph Editor - "Selected = Editable" */
if (sipo->flag & SIPO_SELCUVERTSONLY) {
sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
}
else {
sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
}
/* sync settings with current view status, then return appropriate data */
switch (sipo->mode) {
case SIPO_MODE_ANIMATION: /* Animation F-Curve Editor */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
sipo->ads->source = (ID *)ac->scene;
sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
ac->datatype = ANIMCONT_FCURVES;
ac->data = sipo->ads;
ac->mode = sipo->mode;
return true;
case SIPO_MODE_DRIVERS: /* Driver F-Curve Editor */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
sipo->ads->source = (ID *)ac->scene;
sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
ac->datatype = ANIMCONT_DRIVERS;
ac->data = sipo->ads;
ac->mode = sipo->mode;
return true;
default: /* unhandled yet */
ac->datatype = ANIMCONT_NONE;
ac->data = NULL;
ac->mode = -1;
return false;
}
}
/* ----------- Private Stuff - NLA Editor ------------- */
/* Get data being edited in Graph Editor (depending on current 'mode') */
static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla)
{
/* init dopesheet data if non-existent (i.e. for old files) */
if (snla->ads == NULL) {
snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
}
ac->ads = snla->ads;
/* sync settings with current view status, then return appropriate data */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
snla->ads->source = (ID *)ac->scene;
snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
ac->datatype = ANIMCONT_NLA;
ac->data = snla->ads;
return true;
}
/* ----------- Public API --------------- */
/* Obtain current anim-data context,
* given that context info from Blender context has already been set:
* - AnimContext to write to is provided as pointer to var on stack so that we don't have
* allocation/freeing costs (which are not that avoidable with channels).
*/
bool ANIM_animdata_context_getdata(bAnimContext *ac)
{
SpaceLink *sl = ac->sl;
bool ok = false;
/* context depends on editor we are currently in */
if (sl) {
switch (ac->spacetype) {
case SPACE_ACTION: {
SpaceAction *saction = (SpaceAction *)sl;
ok = actedit_get_context(ac, saction);
break;
}
case SPACE_GRAPH: {
SpaceGraph *sipo = (SpaceGraph *)sl;
ok = graphedit_get_context(ac, sipo);
break;
}
case SPACE_NLA: {
SpaceNla *snla = (SpaceNla *)sl;
ok = nlaedit_get_context(ac, snla);
break;
}
}
}
/* check if there's any valid data */
return (ok && ac->data);
}
/* Obtain current anim-data context from Blender Context info
* - AnimContext to write to is provided as pointer to var on stack so that we don't have
* allocation/freeing costs (which are not that avoidable with channels).
* - Clears data and sets the information from Blender Context which is useful
*/
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
{
Main *bmain = CTX_data_main(C);
ScrArea *area = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
SpaceLink *sl = CTX_wm_space_data(C);
Scene *scene = CTX_data_scene(C);
/* clear old context info */
if (ac == NULL) {
return false;
}
memset(ac, 0, sizeof(bAnimContext));
/* get useful default context settings from context */
ac->bmain = bmain;
ac->scene = scene;
if (scene) {
ac->markers = ED_context_get_markers(C);
}
ac->view_layer = CTX_data_view_layer(C);
ac->depsgraph = CTX_data_depsgraph_pointer(C);
ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL;
ac->area = area;
ac->region = region;
ac->sl = sl;
ac->spacetype = (area) ? area->spacetype : 0;
ac->regiontype = (region) ? region->regiontype : 0;
/* Initialize default y-scale factor. */
animedit_get_yscale_factor(ac);
/* get data context info */
/* XXX: if the below fails, try to grab this info from context instead...
* (to allow for scripting). */
return ANIM_animdata_context_getdata(ac);
}
/* ************************************************************ */
/* Blender Data <-- Filter --> Channels to be operated on */
/* macros to use before/after getting the sub-channels of some channel,
* to abstract away some of the tricky logic involved
*
* cases:
* 1) Graph Edit main area (just data) OR channels visible in Channel List
* 2) If not showing channels, we're only interested in the data (Action Editor's editing)
* 3) We don't care what data, we just care there is some (so that a collapsed
* channel can be kept around). No need to clear channels-flag in order to
* keep expander channels with no sub-data out, as those cases should get
* dealt with by the recursive detection idiom in place.
*
* Implementation Note:
* YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
* to go steamrolling the logic into a single-line expression as from experience,
* those are notoriously difficult to read + debug when extending later on. The code
* below is purposefully laid out so that each case noted above corresponds clearly to
* one case below.
*/
#define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
{ \
int _filter = filter_mode; \
short _doSubChannels = 0; \
if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) { \
_doSubChannels = 1; \
} \
else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) { \
_doSubChannels = 2; \
} \
else { \
filter_mode |= ANIMFILTER_TMP_PEEK; \
} \
\
{ \
(void)_doSubChannels; \
}
/* ... standard sub-channel filtering can go on here now ... */
#define END_ANIMFILTER_SUBCHANNELS \
filter_mode = _filter; \
} \
(void)0
/* ............................... */
/* quick macro to test if AnimData is usable */
#define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
/* quick macro to test if AnimData is usable for drivers */
#define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
/* quick macro to test if AnimData is usable for NLA */
#define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
/**
* Quick macro to test for all three above usability tests, performing the appropriate provided
* action for each when the AnimData context is appropriate.
*
* Priority order for this goes (most important, to least):
* AnimData blocks, NLA, Drivers, Keyframes.
*
* For this to work correctly,
* a standard set of data needs to be available within the scope that this
*
* Gets called in:
* - ListBase anim_data;
* - bDopeSheet *ads;
* - bAnimListElem *ale;
* - size_t items;
*
* - id: ID block which should have an AnimData pointer following it immediately, to use
* - adtOk: line or block of code to execute for AnimData-blocks case
* (usually #ANIMDATA_ADD_ANIMDATA).
* - nlaOk: line or block of code to execute for NLA tracks+strips case
* - driversOk: line or block of code to execute for Drivers case
* - nlaKeysOk: line or block of code for NLA Strip Keyframes case
* - keysOk: line or block of code for Keyframes case
*
* The checks for the various cases are as follows:
* 0) top level: checks for animdata and also that all the F-Curves for the block will be visible
* 1) animdata check: for filtering animdata blocks only
* 2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
* 2B) actions to convert to nla: include animdata block's data as there is an action that can be
* converted to a new NLA strip, and the filtering options allow this
* 2C) allow non-animated data-blocks to be included so that data-blocks can be added
* 3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
* 4A) nla strip keyframes: these are the per-strip controls for time and influence
* 4B) normal keyframes: only when there is an active action
*/
#define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, nlaKeysOk, keysOk) \
{ \
if ((id)->adt) { \
if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || \
!((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) { \
if (filter_mode & ANIMFILTER_ANIMDATA) { \
adtOk \
} \
else if (ads->filterflag & ADS_FILTER_ONLYNLA) { \
if (ANIMDATA_HAS_NLA(id)) { \
nlaOk \
} \
else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || ANIMDATA_HAS_KEYS(id)) { \
nlaOk \
} \
} \
else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) { \
if (ANIMDATA_HAS_DRIVERS(id)) { \
driversOk \
} \
} \
else { \
if (ANIMDATA_HAS_NLA(id)) { \
nlaKeysOk \
} \
if (ANIMDATA_HAS_KEYS(id)) { \
keysOk \
} \
} \
} \
} \
} \
(void)0
/* ............................... */
/* Add a new animation channel, taking into account the "peek" flag, which is used to just check
* whether any channels will be added (but without needing them to actually get created).
*
* ! This causes the calling function to return early if we're only "peeking" for channels
*/
// XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
#define ANIMCHANNEL_NEW_CHANNEL_FULL( \
channel_data, channel_type, owner_id, fcurve_owner_id, ale_statement) \
if (filter_mode & ANIMFILTER_TMP_PEEK) \
return 1; \
{ \
bAnimListElem *ale = make_new_animlistelem( \
channel_data, channel_type, (ID *)owner_id, fcurve_owner_id); \
if (ale) { \
BLI_addtail(anim_data, ale); \
items++; \
ale_statement \
} \
} \
(void)0
#define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id, fcurve_owner_id) \
ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, fcurve_owner_id, {})
/* ............................... */
/* quick macro to test if an anim-channel representing an AnimData block is suitably active */
#define ANIMCHANNEL_ACTIVEOK(ale) \
(!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE))
/* Quick macro to test if an anim-channel (F-Curve, Group, etc.)
* is selected in an acceptable way. */
#define ANIMCHANNEL_SELOK(test_func) \
(!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \
((filter_mode & ANIMFILTER_SEL) && test_func) || \
((filter_mode & ANIMFILTER_UNSEL) && test_func == 0))
/* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
* - _SELEDIT means that only selected curves will have visible+editable keyframes
*
* checks here work as follows:
* 1) seledit off - don't need to consider the implications of this option
* 2) foredit off - we're not considering editing, so channel is ok still
* 3) test_func (i.e. selection test) - only if selected, this test will pass
*/
#define ANIMCHANNEL_SELEDITOK(test_func) \
(!(filter_mode & ANIMFILTER_SELEDIT) || !(filter_mode & ANIMFILTER_FOREDIT) || (test_func))
/* ----------- 'Private' Stuff --------------- */
/* this function allocates memory for a new bAnimListElem struct for the
* provided animation channel-data.
*/
static bAnimListElem *make_new_animlistelem(void *data,
short datatype,
ID *owner_id,
ID *fcurve_owner_id)
{
bAnimListElem *ale = NULL;
/* only allocate memory if there is data to convert */
if (data) {
/* allocate and set generic data */
ale = MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
ale->data = data;
ale->type = datatype;
ale->id = owner_id;
ale->adt = BKE_animdata_from_id(owner_id);
ale->fcurve_owner_id = fcurve_owner_id;
/* do specifics */
switch (datatype) {
case ANIMTYPE_SUMMARY: {
/* Nothing to include for now... this is just a dummy wrapper around
* all the other channels in the DopeSheet, and gets included at the start of the list. */
ale->key_data = NULL;
ale->datatype = ALE_ALL;
break;
}
case ANIMTYPE_SCENE: {
Scene *sce = (Scene *)data;
ale->flag = sce->flag;
ale->key_data = sce;
ale->datatype = ALE_SCE;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_OBJECT: {
Base *base = (Base *)data;
Object *ob = base->object;
ale->flag = ob->flag;
ale->key_data = ob;
ale->datatype = ALE_OB;
ale->adt = BKE_animdata_from_id(&ob->id);
break;
}
case ANIMTYPE_FILLACTD: {
bAction *act = (bAction *)data;
ale->flag = act->flag;
ale->key_data = act;
ale->datatype = ALE_ACT;
break;
}
case ANIMTYPE_FILLDRIVERS: {
AnimData *adt = (AnimData *)data;
ale->flag = adt->flag;
// XXX... drivers don't show summary for now
ale->key_data = NULL;
ale->datatype = ALE_NONE;
break;
}
case ANIMTYPE_DSMAT: {
Material *ma = (Material *)data;
AnimData *adt = ma->adt;
ale->flag = FILTER_MAT_OBJD(ma);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSLAM: {
Light *la = (Light *)data;
AnimData *adt = la->adt;
ale->flag = FILTER_LAM_OBJD(la);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSCAM: {
Camera *ca = (Camera *)data;
AnimData *adt = ca->adt;
ale->flag = FILTER_CAM_OBJD(ca);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSCACHEFILE: {
CacheFile *cache_file = (CacheFile *)data;
AnimData *adt = cache_file->adt;
ale->flag = FILTER_CACHEFILE_OBJD(cache_file);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSCUR: {
Curve *cu = (Curve *)data;
AnimData *adt = cu->adt;
ale->flag = FILTER_CUR_OBJD(cu);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSARM: {
bArmature *arm = (bArmature *)data;
AnimData *adt = arm->adt;
ale->flag = FILTER_ARM_OBJD(arm);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSMESH: {
Mesh *me = (Mesh *)data;
AnimData *adt = me->adt;
ale->flag = FILTER_MESH_OBJD(me);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSLAT: {
Lattice *lt = (Lattice *)data;
AnimData *adt = lt->adt;
ale->flag = FILTER_LATTICE_OBJD(lt);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSSPK: {
Speaker *spk = (Speaker *)data;
AnimData *adt = spk->adt;
ale->flag = FILTER_SPK_OBJD(spk);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSHAIR: {
Hair *hair = (Hair *)data;
AnimData *adt = hair->adt;
ale->flag = FILTER_HAIR_OBJD(hair);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSPOINTCLOUD: {
PointCloud *pointcloud = (PointCloud *)data;
AnimData *adt = pointcloud->adt;
ale->flag = FILTER_POINTS_OBJD(pointcloud);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSVOLUME: {
Volume *volume = (Volume *)data;
AnimData *adt = volume->adt;
ale->flag = FILTER_VOLUME_OBJD(volume);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSSIMULATION: {
Simulation *simulation = (Simulation *)data;
AnimData *adt = simulation->adt;
ale->flag = FILTER_SIMULATION_OBJD(simulation);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSSKEY: {
Key *key = (Key *)data;
AnimData *adt = key->adt;
ale->flag = FILTER_SKE_OBJD(key);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSWOR: {
World *wo = (World *)data;
AnimData *adt = wo->adt;
ale->flag = FILTER_WOR_SCED(wo);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSNTREE: {
bNodeTree *ntree = (bNodeTree *)data;
AnimData *adt = ntree->adt;
ale->flag = FILTER_NTREE_DATA(ntree);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSLINESTYLE: {
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)data;
AnimData *adt = linestyle->adt;
ale->flag = FILTER_LS_SCED(linestyle);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSPART: {
ParticleSettings *part = (ParticleSettings *)ale->data;
AnimData *adt = part->adt;
ale->flag = FILTER_PART_OBJD(part);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSTEX: {
Tex *tex = (Tex *)data;
AnimData *adt = tex->adt;
ale->flag = FILTER_TEX_DATA(tex);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSGPENCIL: {
bGPdata *gpd = (bGPdata *)data;
AnimData *adt = gpd->adt;
/* NOTE: we just reuse the same expand filter for this case */
ale->flag = EXPANDED_GPD(gpd);
// XXX: currently, this is only used for access to its animation data
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_DSMCLIP: {
MovieClip *clip = (MovieClip *)data;
AnimData *adt = clip->adt;
ale->flag = EXPANDED_MCLIP(clip);
ale->key_data = (adt) ? adt->action : NULL;
ale->datatype = ALE_ACT;
ale->adt = BKE_animdata_from_id(data);
break;
}
case ANIMTYPE_NLACONTROLS: {
AnimData *adt = (AnimData *)data;
ale->flag = adt->flag;
ale->key_data = NULL;
ale->datatype = ALE_NONE;
break;
}
case ANIMTYPE_GROUP: {
bActionGroup *agrp = (bActionGroup *)data;
ale->flag = agrp->flag;
ale->key_data = NULL;
ale->datatype = ALE_GROUP;
break;
}
case ANIMTYPE_FCURVE:
case ANIMTYPE_NLACURVE: /* practically the same as ANIMTYPE_FCURVE.
* Differences are applied post-creation */
{
FCurve *fcu = (FCurve *)data;
ale->flag = fcu->flag;
ale->key_data = fcu;
ale->datatype = ALE_FCURVE;
break;
}
case ANIMTYPE_SHAPEKEY: {
KeyBlock *kb = (KeyBlock *)data;
Key *key = (Key *)ale->id;
ale->flag = kb->flag;
/* whether we have keyframes depends on whether there is a Key block to find it from */
if (key) {
/* index of shapekey is defined by place in key's list */
ale->index = BLI_findindex(&key->block, kb);
/* the corresponding keyframes are from the animdata */
if (ale->adt && ale->adt->action) {
bAction *act = ale->adt->action;
char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
/* try to find the F-Curve which corresponds to this exactly,
* then free the MEM_alloc'd string
*/
if (rna_path) {
ale->key_data = (void *)BKE_fcurve_find(&act->curves, rna_path, 0);
MEM_freeN(rna_path);
}
}
ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
}
break;
}
case ANIMTYPE_GPLAYER: {
bGPDlayer *gpl = (bGPDlayer *)data;
ale->flag = gpl->flag;
ale->key_data = NULL;
ale->datatype = ALE_GPFRAME;
break;
}
case ANIMTYPE_MASKLAYER: {
MaskLayer *masklay = (MaskLayer *)data;
ale->flag = masklay->flag;
ale->key_data = NULL;
ale->datatype = ALE_MASKLAY;
break;
}
case ANIMTYPE_NLATRACK: {
NlaTrack *nlt = (NlaTrack *)data;
ale->flag = nlt->flag;
ale->key_data = &nlt->strips;
ale->datatype = ALE_NLASTRIP;
break;
}
case ANIMTYPE_NLAACTION: {
/* nothing to include for now... nothing editable from NLA-perspective here */
ale->key_data = NULL;
ale->datatype = ALE_NONE;
break;
}
}
}
/* return created datatype */
return ale;
}
/* ----------------------------------------- */
/* 'Only Selected' selected data and/or 'Include Hidden' filtering
* NOTE: when this function returns true, the F-Curve is to be skipped
*/
static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
{
if (fcu->grp != NULL && fcu->grp->flag & ADT_CURVES_ALWAYS_VISIBLE) {
return false;
}
/* hidden items should be skipped if we only care about visible data,
* but we aren't interested in hidden stuff */
const bool skip_hidden = (filter_mode & ANIMFILTER_DATA_VISIBLE) &&
!(ads->filterflag & ADS_FILTER_INCL_HIDDEN);
if (GS(owner_id->name) == ID_OB) {
Object *ob = (Object *)owner_id;
/* only consider if F-Curve involves pose.bones */
if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
bPoseChannel *pchan;
char *bone_name;
/* get bone-name, and check if this bone is selected */
bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
if (bone_name) {
MEM_freeN(bone_name);
}
/* check whether to continue or skip */
if ((pchan) && (pchan->bone)) {
/* If only visible channels,
* skip if bone not visible unless user wants channels from hidden data too. */
if (skip_hidden) {
bArmature *arm = (bArmature *)ob->data;
/* skipping - not visible on currently visible layers */
if ((arm->layer & pchan->bone->layer) == 0) {
return true;
}
/* skipping - is currently hidden */
if (pchan->bone->flag & BONE_HIDDEN_P) {
return true;
}
}
/* can only add this F-Curve if it is selected */
if (ads->filterflag & ADS_FILTER_ONLYSEL) {
if ((pchan->bone->flag & BONE_SELECTED) == 0) {
return true;
}
}
}
}
}
else if (GS(owner_id->name) == ID_SCE) {
Scene *scene = (Scene *)owner_id;
/* only consider if F-Curve involves sequence_editor.sequences */
if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
Editing *ed = BKE_sequencer_editing_get(scene, false);
Sequence *seq = NULL;
char *seq_name;
if (ed) {
/* get strip name, and check if this strip is selected */
seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
if (seq_name) {
MEM_freeN(seq_name);
}
}
/* can only add this F-Curve if it is selected */
if (ads->filterflag & ADS_FILTER_ONLYSEL) {
if ((seq == NULL) || (seq->flag & SELECT) == 0) {
return true;
}
}
}
}
else if (GS(owner_id->name) == ID_NT) {
bNodeTree *ntree = (bNodeTree *)owner_id;
/* check for selected nodes */
if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
bNode *node;
char *node_name;
/* get strip name, and check if this strip is selected */
node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
node = nodeFindNodebyName(ntree, node_name);
if (node_name) {
MEM_freeN(node_name);
}
/* can only add this F-Curve if it is selected */
if (ads->filterflag & ADS_FILTER_ONLYSEL) {
if ((node) && (node->flag & NODE_SELECT) == 0) {
return true;
}
}
}
}
return false;
}
/* Helper for name-based filtering - Perform "partial/fuzzy matches" (as in 80a7efd) */
static bool name_matches_dopesheet_filter(bDopeSheet *ads, char *name)
{
if (ads->flag & ADS_FLAG_FUZZY_NAMES) {
/* full fuzzy, multi-word, case insensitive matches */
const size_t str_len = strlen(ads->searchstr);
const int words_max = BLI_string_max_possible_word_count(str_len);
int(*words)[2] = BLI_array_alloca(words, words_max);
const int words_len = BLI_string_find_split_words(
ads->searchstr, str_len, ' ', words, words_max);
bool found = false;
/* match name against all search words */
for (int index = 0; index < words_len; index++) {
if (BLI_strncasestr(name, ads->searchstr + words[index][0], words[index][1])) {
found = true;
break;
}
}
/* if we have a match somewhere, this returns true */
return found;
}
/* fallback/default - just case insensitive, but starts from start of word */
return BLI_strcasestr(name, ads->searchstr) != NULL;
}
/* (Display-)Name-based F-Curve filtering
* NOTE: when this function returns true, the F-Curve is to be skipped
*/
static bool skip_fcurve_with_name(
bDopeSheet *ads, FCurve *fcu, eAnim_ChannelType channel_type, void *owner, ID *owner_id)
{
bAnimListElem ale_dummy = {NULL};
const bAnimChannelType *acf;
/* create a dummy wrapper for the F-Curve, so we can get typeinfo for it */
ale_dummy.type = channel_type;
ale_dummy.owner = owner;
ale_dummy.id = owner_id;
ale_dummy.data = fcu;
/* get type info for channel */
acf = ANIM_channel_get_typeinfo(&ale_dummy);
if (acf && acf->name) {
char name[256]; /* hopefully this will be enough! */
/* get name */
acf->name(&ale_dummy, name);
/* check for partial match with the match string, assuming case insensitive filtering
* if match, this channel shouldn't be ignored!
*/
return !name_matches_dopesheet_filter(ads, name);
}
/* just let this go... */
return true;
}
/**
* Check if F-Curve has errors and/or is disabled
*
* \return true if F-Curve has errors/is disabled
*/
static bool fcurve_has_errors(FCurve *fcu)
{
/* F-Curve disabled - path eval error */
if (fcu->flag & FCURVE_DISABLED) {
return true;
}
/* driver? */
if (fcu->driver) {
ChannelDriver *driver = fcu->driver;
DriverVar *dvar;
/* error flag on driver usually means that there is an error
* BUT this may not hold with PyDrivers as this flag gets cleared
* if no critical errors prevent the driver from working...
*/
if (driver->flag & DRIVER_FLAG_INVALID) {
return true;
}
/* check variables for other things that need linting... */
// TODO: maybe it would be more efficient just to have a quick flag for this?
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
if (dtar->flag & DTAR_FLAG_INVALID) {
return true;
}
}
DRIVER_TARGETS_LOOPER_END;
}
}
/* no errors found */
return false;
}
/* find the next F-Curve that is usable for inclusion */
static FCurve *animfilter_fcurve_next(bDopeSheet *ads,
FCurve *first,
eAnim_ChannelType channel_type,
int filter_mode,
void *owner,
ID *owner_id)
{
bActionGroup *grp = (channel_type == ANIMTYPE_FCURVE) ? owner : NULL;
FCurve *fcu = NULL;
/* Loop over F-Curves - assume that the caller of this has already checked
* that these should be included.
* NOTE: we need to check if the F-Curves belong to the same group,
* as this gets called for groups too...
*/
for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) {
/* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
* - The 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data
* which can be independently selected/hidden, such as Pose-Channels, Sequence Strips,
* and Nodes. Since these checks were traditionally done as first check for objects,
* we do the same here.
* - We currently use an 'approximate' method for getting these F-Curves that doesn't require
* carefully checking the entire path.
* - This will also affect things like Drivers, and also works for Bone Constraints.
*/
if (ads && owner_id) {
if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) {
if ((ads->filterflag & ADS_FILTER_ONLYSEL) ||
(ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) {
if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode)) {
continue;
}
}
}
}
/* only include if visible (Graph Editor check, not channels check) */
if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
/* only work with this channel and its subchannels if it is editable */
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
/* Only include this curve if selected in a way consistent
* with the filtering requirements. */
if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) {
/* only include if this curve is active */
if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
/* name based filtering... */
if (((ads) && (ads->searchstr[0] != '\0')) && (owner_id)) {
if (skip_fcurve_with_name(ads, fcu, channel_type, owner, owner_id)) {
continue;
}
}
/* error-based filtering... */
if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
/* skip if no errors... */
if (fcurve_has_errors(fcu) == false) {
continue;
}
}
/* this F-Curve can be used, so return it */
return fcu;
}
}
}
}
}
/* no (more) F-Curves from the list are suitable... */
return NULL;
}
static size_t animfilter_fcurves(ListBase *anim_data,
bDopeSheet *ads,
FCurve *first,
eAnim_ChannelType fcurve_type,
int filter_mode,
void *owner,
ID *owner_id,
ID *fcurve_owner_id)
{
FCurve *fcu;
size_t items = 0;
/* Loop over every F-Curve able to be included.
*
* This for-loop works like this:
* 1) The starting F-Curve is assigned to the fcu pointer
* so that we have a starting point to search from.
* 2) The first valid F-Curve to start from (which may include the one given as 'first')
* in the remaining list of F-Curves is found, and verified to be non-null.
* 3) The F-Curve referenced by fcu pointer is added to the list
* 4) The fcu pointer is set to the F-Curve after the one we just added,
* so that we can keep going through the rest of the F-Curve list without an eternal loop.
* Back to step 2 :)
*/
for (fcu = first;
((fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, owner, owner_id)));
fcu = fcu->next) {
if (UNLIKELY(fcurve_type == ANIMTYPE_NLACURVE)) {
/* NLA Control Curve - Basically the same as normal F-Curves,
* except we need to set some stuff differently */
ANIMCHANNEL_NEW_CHANNEL_FULL(fcu, ANIMTYPE_NLACURVE, owner_id, fcurve_owner_id, {
ale->owner = owner; /* strip */
ale->adt = NULL; /* to prevent time mapping from causing problems */
});
}
else {
/* Normal FCurve */
ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id, fcurve_owner_id);
}
}
/* return the number of items added to the list */
return items;
}
static size_t animfilter_act_group(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
bAction *act,
bActionGroup *agrp,
int filter_mode,
ID *owner_id)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
// int ofilter = filter_mode;
/* if we care about the selection status of the channels,
* but the group isn't expanded (1)...
* (1) this only matters if we actually care about the hierarchy though.
* - Hierarchy matters: this hack should be applied
* - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
*/
if (
/* Care about hierarchy but group isn't expanded. */
((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) &&
/* Care about selection status. */
(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL))) {
/* If the group itself isn't selected appropriately,
* we shouldn't consider it's children either. */
if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0) {
return 0;
}
/* if we're still here,
* then the selection status of the curves within this group should not matter,
* since this creates too much overhead for animators (i.e. making a slow workflow).
*
* Tools affected by this at time of coding (2010 Feb 09):
* - Inserting keyframes on selected channels only.
* - Pasting keyframes.
* - Creating ghost curves in Graph Editor.
*/
filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE);
}
/* add grouped F-Curves */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_AGRP(ac, agrp)) {
/* special filter so that we can get just the F-Curves within the active group */
if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
/* for the Graph Editor, curves may be set to not be visible in the view to lessen
* clutter, but to do this, we need to check that the group doesn't have it's
* not-visible flag set preventing all its sub-curves to be shown
*/
if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE)) {
/* group must be editable for its children to be editable (if we care about this) */
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
/* get first F-Curve which can be used here */
FCurve *first_fcu = animfilter_fcurve_next(
ads, agrp->channels.first, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id);
/* filter list, starting from this F-Curve */
tmp_items += animfilter_fcurves(
&tmp_data, ads, first_fcu, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id, &act->id);
}
}
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* add this group as a channel first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* restore original filter mode so that this next step works ok... */
// filter_mode = ofilter;
/* filter selection of channel specially here again,
* since may be open and not subject to previous test */
if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp))) {
ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id, &act->id);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
static size_t animfilter_action(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
bAction *act,
int filter_mode,
ID *owner_id)
{
bActionGroup *agrp;
FCurve *lastchan = NULL;
size_t items = 0;
/* don't include anything from this action if it is linked in from another file,
* and we're getting stuff for editing...
*/
if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act)) {
return 0;
}
/* do groups */
// TODO: do nested groups?
for (agrp = act->groups.first; agrp; agrp = agrp->next) {
/* store reference to last channel of group */
if (agrp->channels.last) {
lastchan = agrp->channels.last;
}
/* action group's channels */
items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
}
/* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
items += animfilter_fcurves(
anim_data, ads, firstfcu, ANIMTYPE_FCURVE, filter_mode, NULL, owner_id, &act->id);
}
/* return the number of items added to the list */
return items;
}
/* Include NLA-Data for NLA-Editor:
* - When ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
* Although the evaluation order is from the first track to the last and then apply the
* Action on top, we present this in the UI as the Active Action followed by the last track
* to the first so that we get the evaluation order presented as per a stack.
* - For normal filtering (i.e. for editing),
* we only need the NLA-tracks but they can be in 'normal' evaluation order, i.e. first to last.
* Otherwise, some tools may get screwed up.
*/
static size_t animfilter_nla(bAnimContext *UNUSED(ac),
ListBase *anim_data,
bDopeSheet *ads,
AnimData *adt,
int filter_mode,
ID *owner_id)
{
NlaTrack *nlt;
NlaTrack *first = NULL, *next = NULL;
size_t items = 0;
/* if showing channels, include active action */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* if NLA action-line filtering is off, don't show unless there are keyframes,
* in order to keep things more compact for doing transforms
*/
if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
/* there isn't really anything editable here, so skip if need editable */
if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
/* Just add the action track now (this MUST appear for drawing):
* - As AnimData may not have an action,
* we pass a dummy pointer just to get the list elem created,
* then overwrite this with the real value - REVIEW THIS.
*/
ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id, NULL, {
ale->data = adt->action ? adt->action : NULL;
});
}
}
/* first track to include will be the last one if we're filtering by channels */
first = adt->nla_tracks.last;
}
else {
/* first track to include will the first one (as per normal) */
first = adt->nla_tracks.first;
}
/* loop over NLA Tracks -
* assume that the caller of this has already checked that these should be included */
for (nlt = first; nlt; nlt = next) {
/* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
next = nlt->prev;
}
else {
next = nlt->next;
}
/* If we're in NLA-tweak-mode, don't show this track if it was disabled
* (due to tweaking) for now:
* - active track should still get shown though (even though it has disabled flag set)
*/
// FIXME: the channels after should still get drawn, just 'differently',
// and after an active-action channel.
if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) &&
(adt->act_track != nlt)) {
continue;
}
/* only work with this channel and its subchannels if it is editable */
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
/* only include this track if selected in a way consistent with the filtering requirements */
if (ANIMCHANNEL_SELOK(SEL_NLT(nlt))) {
/* only include if this track is active */
if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
/* name based filtering... */
if (((ads) && (ads->searchstr[0] != '\0')) && (owner_id)) {
bool track_ok = false, strip_ok = false;
/* check if the name of the track, or the strips it has are ok... */
track_ok = name_matches_dopesheet_filter(ads, nlt->name);
if (track_ok == false) {
NlaStrip *strip;
for (strip = nlt->strips.first; strip; strip = strip->next) {
if (name_matches_dopesheet_filter(ads, strip->name)) {
strip_ok = true;
break;
}
}
}
/* skip if both fail this test... */
if (!track_ok && !strip_ok) {
continue;
}
}
/* add the track now that it has passed all our tests */
ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id, NULL);
}
}
}
}
/* return the number of items added to the list */
return items;
}
/* Include the control FCurves per NLA Strip in the channel list
* NOTE: This is includes the expander too...
*/
static size_t animfilter_nla_controls(
ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add control curves from each NLA strip... */
/* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */
BEGIN_ANIMFILTER_SUBCHANNELS (((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0)) {
NlaTrack *nlt;
NlaStrip *strip;
/* for now, we only go one level deep - so controls on grouped FCurves are not handled */
for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
for (strip = nlt->strips.first; strip; strip = strip->next) {
/* pass strip as the "owner",
* so that the name lookups (used while filtering) will resolve */
/* NLA tracks are coming from AnimData, so owner of f-curves
* is the same as owner of animation data. */
tmp_items += animfilter_fcurves(&tmp_data,
ads,
strip->fcurves.first,
ANIMTYPE_NLACURVE,
filter_mode,
strip,
owner_id,
owner_id);
}
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* add the expander as a channel first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* currently these channels cannot be selected, so they should be skipped */
if ((filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) == 0) {
ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_NLACONTROLS, owner_id, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* determine what animation data from AnimData block should get displayed */
static size_t animfilter_block_data(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
{
AnimData *adt = BKE_animdata_from_id(id);
size_t items = 0;
/* image object data-blocks have no anim-data so check for NULL */
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id;
/* NOTE: this macro is used instead of inlining the logic here,
* since this sort of filtering is still needed in a few places in the rest of the code still -
* notably for the few cases where special mode-based
* different types of data expanders are required.
*/
ANIMDATA_FILTER_CASES(
iat,
{ /* AnimData */
/* specifically filter animdata block */
if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(adt))) {
ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id, NULL);
}
},
{ /* NLA */
items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
},
{ /* Drivers */
items += animfilter_fcurves(
anim_data, ads, adt->drivers.first, ANIMTYPE_FCURVE, filter_mode, NULL, id, id);
},
{ /* NLA Control Keyframes */
items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, id);
},
{ /* Keyframes */
items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
});
}
return items;
}
/* Include ShapeKey Data for ShapeKey Editor */
static size_t animdata_filter_shapekey(bAnimContext *ac,
ListBase *anim_data,
Key *key,
int filter_mode)
{
size_t items = 0;
/* check if channels or only F-Curves */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
KeyBlock *kb;
/* loop through the channels adding ShapeKeys as appropriate */
for (kb = key->block.first; kb; kb = kb->next) {
/* skip the first one, since that's the non-animatable basis */
if (kb == key->block.first) {
continue;
}
/* only work with this channel and its subchannels if it is editable */
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
/* Only include this track if selected in a way consistent
* with the filtering requirements. */
if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb))) {
// TODO: consider 'active' too?
/* owner-id here must be key so that the F-Curve can be resolved... */
ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key, NULL);
}
}
}
}
else {
/* just use the action associated with the shapekey */
// TODO: somehow manage to pass dopesheet info down here too?
if (key->adt) {
if (filter_mode & ANIMFILTER_ANIMDATA) {
if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(key->adt))) {
ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key, NULL);
}
}
else if (key->adt->action) {
items = animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
}
}
}
/* return the number of items added to the list */
return items;
}
/* Helper for Grease Pencil - layers within a data-block. */
static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data,
bDopeSheet *ads,
bGPdata *gpd,
int filter_mode)
{
bGPDlayer *gpl;
size_t items = 0;
/* loop over layers as the conditions are acceptable (top-Down order) */
for (gpl = gpd->layers.last; gpl; gpl = gpl->prev) {
/* only if selected */
if (!ANIMCHANNEL_SELOK(SEL_GPL(gpl))) {
continue;
}
/* only if editable */
if ((filter_mode & ANIMFILTER_FOREDIT) && !EDITABLE_GPL(gpl)) {
continue;
}
/* active... */
if ((filter_mode & ANIMFILTER_ACTIVE) && (gpl->flag & GP_LAYER_ACTIVE) == 0) {
continue;
}
/* skip layer if the name doesn't match the filter string */
if (ads != NULL && ads->searchstr[0] != '\0' &&
name_matches_dopesheet_filter(ads, gpl->info) == false) {
continue;
}
/* Skip empty layers. */
if (BLI_listbase_is_empty(&gpl->frames)) {
continue;
}
/* add to list */
ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd, NULL);
}
return items;
}
/* Helper for Grease Pencil - Grease Pencil data-block - GP Frames. */
static size_t animdata_filter_gpencil_data(ListBase *anim_data,
bDopeSheet *ads,
bGPdata *gpd,
int filter_mode)
{
size_t items = 0;
/* When asked from "AnimData" blocks (i.e. the top-level containers for normal animation),
* for convenience, this will return GP Data-blocks instead.
* This may cause issues down the track, but for now, this will do.
*/
if (filter_mode & ANIMFILTER_ANIMDATA) {
/* just add GPD as a channel - this will add everything needed */
ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, gpd, NULL);
}
else {
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
/* add gpencil animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_GPD(gpd)) {
tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* add gpd as channel too (if for drawing, and it has layers) */
ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL, NULL);
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
}
return items;
}
/* Grab all Grease Pencil data-blocks in file. */
// TODO: should this be amalgamated with the dopesheet filtering code?
static size_t animdata_filter_gpencil(bAnimContext *ac,
ListBase *anim_data,
void *UNUSED(data),
int filter_mode)
{
bDopeSheet *ads = ac->ads;
size_t items = 0;
ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
Base *base;
/* Include all annotation datablocks. */
if (((ads->filterflag & ADS_FILTER_ONLYSEL) == 0) ||
(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
LISTBASE_FOREACH (bGPdata *, gpd, &ac->bmain->gpencils) {
if (gpd->flag & GP_DATA_ANNOTATIONS) {
items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode);
}
}
}
/* Objects in the scene */
for (base = view_layer->object_bases.first; base; base = base->next) {
/* Only consider this object if it has got some GP data (saving on all the other tests) */
if (base->object && (base->object->type == OB_GPENCIL)) {
Object *ob = base->object;
/* firstly, check if object can be included, by the following factors:
* - if only visible, must check for layer and also viewport visibility
* --> while tools may demand only visible, user setting takes priority
* as user option controls whether sets of channels get included while
* tool-flag takes into account collapsed/open channels too
* - if only selected, must check if object is selected
* - there must be animation data to edit (this is done recursively as we
* try to add the channels)
*/
if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
/* Layer visibility - we check both object and base,
* since these may not be in sync yet. */
if ((base->flag & BASE_VISIBLE_DEPSGRAPH) == 0) {
continue;
}
/* outliner restrict-flag */
if (ob->restrictflag & OB_RESTRICT_VIEWPORT) {
continue;
}
}
/* check selection and object type filters */
if ((ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED))) {
/* only selected should be shown */
continue;
}
/* check if object belongs to the filtering group if option to filter
* objects by the grouped status is on
* - used to ease the process of doing multiple-character choreographies
*/
if (ads->filter_grp != NULL) {
if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) {
continue;
}
}
/* finally, include this object's grease pencil data-block. */
/* XXX: Should we store these under expanders per item? */
items += animdata_filter_gpencil_data(anim_data, ads, ob->data, filter_mode);
}
}
/* return the number of items added to the list */
return items;
}
/* Helper for Grease Pencil data integrated with main DopeSheet */
static size_t animdata_filter_ds_gpencil(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add relevant animation channels for Grease Pencil */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_GPD(gpd)) {
/* add animation channels */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode);
/* add Grease Pencil layers */
// TODO: do these need a separate expander?
// XXX: what order should these go in?
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
// XXX: active check here needs checking
if (ANIMCHANNEL_ACTIVEOK(gpd)) {
ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_DSGPENCIL, gpd, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* Helper for Cache File data integrated with main DopeSheet */
static size_t animdata_filter_ds_cachefile(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, CacheFile *cache_file, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add relevant animation channels for Cache File */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_CACHEFILE_OBJD(cache_file)) {
/* add animation channels */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, &cache_file->id, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
// XXX: active check here needs checking
if (ANIMCHANNEL_ACTIVEOK(cache_file)) {
ANIMCHANNEL_NEW_CHANNEL(cache_file, ANIMTYPE_DSCACHEFILE, cache_file, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* Helper for Mask Editing - mask layers */
static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const int filter_mode)
{
MaskLayer *masklay_act = BKE_mask_layer_active(mask);
MaskLayer *masklay;
size_t items = 0;
/* loop over layers as the conditions are acceptable */
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
/* only if selected */
if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay))) {
/* only if editable */
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) {
/* active... */
if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) {
/* add to list */
ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask, NULL);
}
}
}
}
return items;
}
/* Grab all mask data */
static size_t animdata_filter_mask(Main *bmain,
ListBase *anim_data,
void *UNUSED(data),
int filter_mode)
{
Mask *mask;
size_t items = 0;
/* For now, grab mask data-blocks directly from main. */
// XXX: this is not good...
for (mask = bmain->masks.first; mask; mask = mask->id.next) {
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
/* only show if mask is used by something... */
if (ID_REAL_USERS(mask) < 1) {
continue;
}
/* add mask animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_MASK(mask)) {
tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* add mask data-block as channel too (if for drawing, and it has layers) */
ANIMCHANNEL_NEW_CHANNEL(mask, ANIMTYPE_MASKDATABLOCK, NULL, NULL);
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
}
/* return the number of items added to the list */
return items;
}
/* NOTE: owner_id is scene, material, or texture block,
* which is the direct owner of the node tree in question. */
static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
ID *owner_id,
bNodeTree *ntree,
int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add nodetree animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_NTREE_DATA(ntree)) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(ntree)) {
ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_ds_nodetree(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
ID *owner_id,
bNodeTree *ntree,
int filter_mode)
{
bNode *node;
size_t items = 0;
items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, ntree, filter_mode);
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_GROUP) {
if (node->id) {
if ((ads->filterflag & ADS_FILTER_ONLYSEL) && (node->flag & NODE_SELECT) == 0) {
continue;
}
/* Recurse into the node group */
items += animdata_filter_ds_nodetree(ac,
anim_data,
ads,
owner_id,
(bNodeTree *)node->id,
filter_mode | ANIMFILTER_TMP_IGNORE_ONLYSEL);
}
}
}
return items;
}
static size_t animdata_filter_ds_linestyle(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
{
ViewLayer *view_layer;
FreestyleLineSet *lineset;
size_t items = 0;
for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
if (lineset->linestyle) {
lineset->linestyle->id.tag |= LIB_TAG_DOIT;
}
}
}
for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
/* skip render layers without Freestyle enabled */
if ((view_layer->flag & VIEW_LAYER_FREESTYLE) == 0) {
continue;
}
/* loop over linesets defined in the render layer */
for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
FreestyleLineStyle *linestyle = lineset->linestyle;
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
if ((linestyle == NULL) || !(linestyle->id.tag & LIB_TAG_DOIT)) {
continue;
}
linestyle->id.tag &= ~LIB_TAG_DOIT;
/* add scene-level animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_LS_SCED(linestyle)) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include anim-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(linestyle)) {
ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
}
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_ds_texture(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
Tex *tex,
ID *owner_id,
int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add texture's animation data to temp collection */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_TEX_DATA(tex)) {
/* texture animdata */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
/* nodes */
if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
/* owner_id as id instead of texture,
* since it'll otherwise be impossible to track the depth. */
// FIXME: perhaps as a result, textures should NOT be included under materials,
// but under their own section instead so that free-floating textures can also be animated.
tmp_items += animdata_filter_ds_nodetree(
ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include texture-expand widget? */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(tex)) {
ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* NOTE: owner_id is the direct owner of the texture stack in question
* It used to be Material/Light/World before the Blender Internal removal for 2.8
*/
static size_t animdata_filter_ds_textures(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
{
MTex **mtex = NULL;
size_t items = 0;
int a = 0;
/* get datatype specific data first */
if (owner_id == NULL) {
return 0;
}
switch (GS(owner_id->name)) {
case ID_PA: {
ParticleSettings *part = (ParticleSettings *)owner_id;
mtex = (MTex **)(&part->mtex);
break;
}
default: {
/* invalid/unsupported option */
if (G.debug & G_DEBUG) {
printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n",
owner_id->name);
}
return 0;
}
}
/* Firstly check that we actually have some textures,
* by gathering all textures in a temp list. */
for (a = 0; a < MAX_MTEX; a++) {
Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL;
/* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
if (tex == NULL) {
continue;
}
/* add texture's anim channels */
items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode);
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_ds_material(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Material *ma, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add material's animation data to temp collection */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_MAT_OBJD(ma)) {
/* material's animation data */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
/* nodes */
if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
tmp_items += animdata_filter_ds_nodetree(
ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include material-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(ma)) {
ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
return items;
}
static size_t animdata_filter_ds_materials(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
{
size_t items = 0;
int a = 0;
/* First pass: take the materials referenced via the Material slots of the object. */
for (a = 1; a <= ob->totcol; a++) {
Material *ma = BKE_object_material_get(ob, a);
/* if material is valid, try to add relevant contents from here */
if (ma) {
/* add channels */
items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
}
}
/* return the number of items added to the list */
return items;
}
/* ............ */
/* Temporary context for modifier linked-data channel extraction */
typedef struct tAnimFilterModifiersContext {
bAnimContext *ac; /* anim editor context */
bDopeSheet *ads; /* dopesheet filtering settings */
ListBase tmp_data; /* list of channels created (but not yet added to the main list) */
size_t items; /* number of channels created */
int filter_mode; /* flags for stuff we want to filter */
} tAnimFilterModifiersContext;
/* dependency walker callback for modifier dependencies */
static void animfilter_modifier_idpoin_cb(void *afm_ptr,
Object *ob,
ID **idpoin,
int UNUSED(cb_flag))
{
tAnimFilterModifiersContext *afm = (tAnimFilterModifiersContext *)afm_ptr;
ID *owner_id = &ob->id;
ID *id = *idpoin;
/* NOTE: the walker only guarantees to give us all the ID-ptr *slots*,
* not just the ones which are actually used, so be careful!
*/
if (id == NULL) {
return;
}
/* check if this is something we're interested in... */
switch (GS(id->name)) {
case ID_TE: /* Textures */
{
Tex *tex = (Tex *)id;
if (!(afm->ads->filterflag & ADS_FILTER_NOTEX)) {
afm->items += animdata_filter_ds_texture(
afm->ac, &afm->tmp_data, afm->ads, tex, owner_id, afm->filter_mode);
}
break;
}
/* TODO: images? */
default:
break;
}
}
/* animation linked to data used by modifiers
* NOTE: strictly speaking, modifier animation is already included under Object level
* but for some modifiers (e.g. Displace), there can be linked data that has settings
* which would be nice to animate (i.e. texture parameters) but which are not actually
* attached to any other objects/materials/etc. in the scene
*/
// TODO: do we want an expander for this?
static size_t animdata_filter_ds_modifiers(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
{
tAnimFilterModifiersContext afm = {NULL};
size_t items = 0;
/* 1) create a temporary "context" containing all the info we have here to pass to the callback
* use to walk through the dependencies of the modifiers
*
* Assumes that all other unspecified values (i.e. accumulation buffers)
* are zero'd out properly!
*/
afm.ac = ac;
afm.ads = ads;
afm.filter_mode = filter_mode;
/* 2) walk over dependencies */
BKE_modifiers_foreach_ID_link(ob, animfilter_modifier_idpoin_cb, &afm);
/* 3) extract data from the context, merging it back into the standard list */
if (afm.items) {
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &afm.tmp_data);
BLI_assert(BLI_listbase_is_empty(&afm.tmp_data));
items += afm.items;
}
return items;
}
/* ............ */
static size_t animdata_filter_ds_particles(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
{
ParticleSystem *psys;
size_t items = 0;
for (psys = ob->particlesystem.first; psys; psys = psys->next) {
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
/* Note that when psys->part->adt is NULL the textures can still be
* animated. */
if (psys->part == NULL) {
continue;
}
/* add particle-system's animation data to temp collection */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_PART_OBJD(psys->part)) {
/* particle system's animation data */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
/* textures */
if (!(ads->filterflag & ADS_FILTER_NOTEX)) {
tmp_items += animdata_filter_ds_textures(
ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include particle-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(psys->part)) {
ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_ds_obdata(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
IdAdtTemplate *iat = ob->data;
short type = 0, expanded = 0;
/* get settings based on data type */
switch (ob->type) {
case OB_CAMERA: /* ------- Camera ------------ */
{
Camera *ca = (Camera *)ob->data;
if (ads->filterflag & ADS_FILTER_NOCAM) {
return 0;
}
type = ANIMTYPE_DSCAM;
expanded = FILTER_CAM_OBJD(ca);
break;
}
case OB_LAMP: /* ---------- Light ----------- */
{
Light *la = (Light *)ob->data;
if (ads->filterflag & ADS_FILTER_NOLAM) {
return 0;
}
type = ANIMTYPE_DSLAM;
expanded = FILTER_LAM_OBJD(la);
break;
}
case OB_CURVE: /* ------- Curve ---------- */
case OB_SURF: /* ------- Nurbs Surface ---------- */
case OB_FONT: /* ------- Text Curve ---------- */
{
Curve *cu = (Curve *)ob->data;
if (ads->filterflag & ADS_FILTER_NOCUR) {
return 0;
}
type = ANIMTYPE_DSCUR;
expanded = FILTER_CUR_OBJD(cu);
break;
}
case OB_MBALL: /* ------- MetaBall ---------- */
{
MetaBall *mb = (MetaBall *)ob->data;
if (ads->filterflag & ADS_FILTER_NOMBA) {
return 0;
}
type = ANIMTYPE_DSMBALL;
expanded = FILTER_MBALL_OBJD(mb);
break;
}
case OB_ARMATURE: /* ------- Armature ---------- */
{
bArmature *arm = (bArmature *)ob->data;
if (ads->filterflag & ADS_FILTER_NOARM) {
return 0;
}
type = ANIMTYPE_DSARM;
expanded = FILTER_ARM_OBJD(arm);
break;
}
case OB_MESH: /* ------- Mesh ---------- */
{
Mesh *me = (Mesh *)ob->data;
if (ads->filterflag & ADS_FILTER_NOMESH) {
return 0;
}
type = ANIMTYPE_DSMESH;
expanded = FILTER_MESH_OBJD(me);
break;
}
case OB_LATTICE: /* ---- Lattice ---- */
{
Lattice *lt = (Lattice *)ob->data;
if (ads->filterflag & ADS_FILTER_NOLAT) {
return 0;
}
type = ANIMTYPE_DSLAT;
expanded = FILTER_LATTICE_OBJD(lt);
break;
}
case OB_SPEAKER: /* ---------- Speaker ----------- */
{
Speaker *spk = (Speaker *)ob->data;
type = ANIMTYPE_DSSPK;
expanded = FILTER_SPK_OBJD(spk);
break;
}
case OB_HAIR: /* ---------- Hair ----------- */
{
Hair *hair = (Hair *)ob->data;
if (ads->filterflag2 & ADS_FILTER_NOHAIR) {
return 0;
}
type = ANIMTYPE_DSHAIR;
expanded = FILTER_HAIR_OBJD(hair);
break;
}
case OB_POINTCLOUD: /* ---------- PointCloud ----------- */
{
PointCloud *pointcloud = (PointCloud *)ob->data;
if (ads->filterflag2 & ADS_FILTER_NOPOINTCLOUD) {
return 0;
}
type = ANIMTYPE_DSPOINTCLOUD;
expanded = FILTER_POINTS_OBJD(pointcloud);
break;
}
case OB_VOLUME: /* ---------- Volume ----------- */
{
Volume *volume = (Volume *)ob->data;
if (ads->filterflag2 & ADS_FILTER_NOVOLUME) {
return 0;
}
type = ANIMTYPE_DSVOLUME;
expanded = FILTER_VOLUME_OBJD(volume);
break;
}
}
/* add object data animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (expanded) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
/* sub-data filtering... */
switch (ob->type) {
case OB_LAMP: /* light - textures + nodetree */
{
Light *la = ob->data;
bNodeTree *ntree = la->nodetree;
/* nodetree */
if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
tmp_items += animdata_filter_ds_nodetree(
ac, &tmp_data, ads, &la->id, ntree, filter_mode);
}
break;
}
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(iat)) {
ANIMCHANNEL_NEW_CHANNEL(iat, type, iat, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* shapekey-level animation */
static size_t animdata_filter_ds_keyanim(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add shapekey-level animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_SKE_OBJD(key)) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include key-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
if (ANIMCHANNEL_ACTIVEOK(key)) {
ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* object-level animation */
static size_t animdata_filter_ds_obanim(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
AnimData *adt = ob->adt;
short type = 0, expanded = 1;
void *cdata = NULL;
/* determine the type of expander channels to use */
/* this is the best way to do this for now... */
ANIMDATA_FILTER_CASES(
ob, /* Some useless long comment to prevent wrapping by old clang-format versions... */
{/* AnimData - no channel, but consider data */},
{/* NLA - no channel, but consider data */},
{ /* Drivers */
type = ANIMTYPE_FILLDRIVERS;
cdata = adt;
expanded = EXPANDED_DRVD(adt);
},
{/* NLA Strip Controls - no dedicated channel for now (XXX) */},
{ /* Keyframes */
type = ANIMTYPE_FILLACTD;
cdata = adt->action;
expanded = EXPANDED_ACTC(adt->action);
});
/* add object-level animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (expanded) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include anim-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
if (type != ANIMTYPE_NONE) {
/* NOTE: active-status (and the associated checks) don't apply here... */
ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
/* get animation channels from object2 */
static size_t animdata_filter_dopesheet_ob(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
Object *ob = base->object;
size_t tmp_items = 0;
size_t items = 0;
/* filter data contained under object first */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_OBJC(ob)) {
Key *key = BKE_key_from_object(ob);
/* object-level animation */
if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
}
/* particle deflector textures */
if (ob->pd != NULL && ob->pd->tex != NULL && !(ads->filterflag & ADS_FILTER_NOTEX)) {
tmp_items += animdata_filter_ds_texture(
ac, &tmp_data, ads, ob->pd->tex, &ob->id, filter_mode);
}
/* shape-key */
if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
}
/* modifiers */
if ((ob->modifiers.first) && !(ads->filterflag & ADS_FILTER_NOMODIFIERS)) {
tmp_items += animdata_filter_ds_modifiers(ac, &tmp_data, ads, ob, filter_mode);
}
/* materials */
if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
}
/* object data */
if (ob->data) {
tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
}
/* particles */
if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
}
/* grease pencil */
if ((ob->type == OB_GPENCIL) && (ob->data) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, ob->data, filter_mode);
}
}
END_ANIMFILTER_SUBCHANNELS;
/* if we collected some channels, add these to the new list... */
if (tmp_items) {
/* firstly add object expander if required */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by selection */
/* XXX: double-check on this -
* most of the time, a lot of tools need to filter out these channels! */
if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(ob)) {
ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob, NULL);
}
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added */
return items;
}
static size_t animdata_filter_ds_world(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add world animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (FILTER_WOR_SCED(wo)) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
/* nodes */
if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
tmp_items += animdata_filter_ds_nodetree(
ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
}
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(wo)) {
ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_ds_scene(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
AnimData *adt = sce->adt;
short type = 0, expanded = 1;
void *cdata = NULL;
/* determine the type of expander channels to use */
// this is the best way to do this for now...
ANIMDATA_FILTER_CASES(
sce, /* Some useless long comment to prevent wrapping by old clang-format versions... */
{/* AnimData - no channel, but consider data */},
{/* NLA - no channel, but consider data */},
{ /* Drivers */
type = ANIMTYPE_FILLDRIVERS;
cdata = adt;
expanded = EXPANDED_DRVD(adt);
},
{/* NLA Strip Controls - no dedicated channel for now (XXX) */},
{ /* Keyframes */
type = ANIMTYPE_FILLACTD;
cdata = adt->action;
expanded = EXPANDED_ACTC(adt->action);
});
/* add scene-level animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (expanded) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include anim-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
if (type != ANIMTYPE_NONE) {
/* NOTE: active-status (and the associated checks) don't apply here... */
ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_dopesheet_scene(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* filter data contained under object first */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_SCEC(sce)) {
bNodeTree *ntree = sce->nodetree;
bGPdata *gpd = sce->gpd;
World *wo = sce->world;
/* Action, Drivers, or NLA for Scene */
if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
}
/* world */
if ((wo) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
}
/* nodetree */
if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
}
/* line styles */
if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
}
/* grease pencil */
if ((gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode);
}
/* TODO: one day, when sequencer becomes its own datatype,
* perhaps it should be included here. */
}
END_ANIMFILTER_SUBCHANNELS;
/* if we collected some channels, add these to the new list... */
if (tmp_items) {
/* firstly add object expander if required */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by selection */
if (ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED))) {
/* NOTE: active-status doesn't matter for this! */
ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added */
return items;
}
static size_t animdata_filter_ds_movieclip(
bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, MovieClip *clip, int filter_mode)
{
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
size_t items = 0;
/* add world animation channels */
BEGIN_ANIMFILTER_SUBCHANNELS (EXPANDED_MCLIP(clip)) {
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)clip, filter_mode);
}
END_ANIMFILTER_SUBCHANNELS;
/* did we find anything? */
if (tmp_items) {
/* include data-expand widget first */
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(clip)) {
ANIMCHANNEL_NEW_CHANNEL(clip, ANIMTYPE_DSMCLIP, clip, NULL);
}
}
/* now add the list of collected channels */
BLI_movelisttolist(anim_data, &tmp_data);
BLI_assert(BLI_listbase_is_empty(&tmp_data));
items += tmp_items;
}
/* return the number of items added to the list */
return items;
}
static size_t animdata_filter_dopesheet_movieclips(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
int filter_mode)
{
size_t items = 0;
MovieClip *clip;
for (clip = ac->bmain->movieclips.first; clip != NULL; clip = clip->id.next) {
/* only show if gpd is used by something... */
if (ID_REAL_USERS(clip) < 1) {
continue;
}
items += animdata_filter_ds_movieclip(ac, anim_data, ads, clip, filter_mode);
}
/* return the number of items added to the list */
return items;
}
/* Helper for animdata_filter_dopesheet() - For checking if an object should be included or not */
static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_mode)
{
Object *ob = base->object;
if (base->object == NULL) {
return false;
}
/* firstly, check if object can be included, by the following factors:
* - if only visible, must check for layer and also viewport visibility
* --> while tools may demand only visible, user setting takes priority
* as user option controls whether sets of channels get included while
* tool-flag takes into account collapsed/open channels too
* - if only selected, must check if object is selected
* - there must be animation data to edit (this is done recursively as we
* try to add the channels)
*/
if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
/* layer visibility - we check both object and base, since these may not be in sync yet */
if ((base->flag & BASE_VISIBLE_DEPSGRAPH) == 0 || (base->flag & BASE_VISIBLE_VIEWLAYER) == 0) {
return false;
}
/* outliner restrict-flag */
if (ob->restrictflag & OB_RESTRICT_VIEWPORT) {
return false;
}
}
/* if only F-Curves with visible flags set can be shown, check that
* data-block hasn't been set to invisible.
*/
if (filter_mode & ANIMFILTER_CURVE_VISIBLE) {
if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE)) {
return false;
}
}
/* Pinned curves are visible regardless of selection flags. */
if ((ob->adt) && (ob->adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
return true;
}
/* Special case.
* We don't do recursive checks for pin, but we need to deal with tricky
* setup like animated camera lens without animated camera location.
* Without such special handle here we wouldn't be able to bin such
* camera data only animation to the editor.
*/
if (ob->adt == NULL && ob->data != NULL) {
AnimData *data_adt = BKE_animdata_from_id(ob->data);
if (data_adt != NULL && (data_adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
return true;
}
}
/* check selection and object type filters */
if ((ads->filterflag & ADS_FILTER_ONLYSEL) &&
!((base->flag & BASE_SELECTED) /*|| (base == sce->basact)*/)) {
/* only selected should be shown */
return false;
}
/* check if object belongs to the filtering group if option to filter
* objects by the grouped status is on
* - used to ease the process of doing multiple-character choreographies
*/
if (ads->filter_grp != NULL) {
if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0) {
return false;
}
}
/* no reason to exclude this object... */
return true;
}
/* Helper for animdata_filter_ds_sorted_bases() - Comparison callback for two Base pointers... */
static int ds_base_sorting_cmp(const void *base1_ptr, const void *base2_ptr)
{
const Base *b1 = *((const Base **)base1_ptr);
const Base *b2 = *((const Base **)base2_ptr);
return strcmp(b1->object->id.name + 2, b2->object->id.name + 2);
}
/* Get a sorted list of all the bases - for inclusion in dopesheet (when drawing channels) */
static Base **animdata_filter_ds_sorted_bases(bDopeSheet *ads,
ViewLayer *view_layer,
int filter_mode,
size_t *r_usable_bases)
{
/* Create an array with space for all the bases, but only containing the usable ones */
size_t tot_bases = BLI_listbase_count(&view_layer->object_bases);
size_t num_bases = 0;
Base **sorted_bases = MEM_mallocN(sizeof(Base *) * tot_bases, "Dopesheet Usable Sorted Bases");
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (animdata_filter_base_is_ok(ads, base, filter_mode)) {
sorted_bases[num_bases++] = base;
}
}
/* Sort this list of pointers (based on the names) */
qsort(sorted_bases, num_bases, sizeof(Base *), ds_base_sorting_cmp);
/* Return list of sorted bases */
*r_usable_bases = num_bases;
return sorted_bases;
}
// TODO: implement pinning...
// (if and when pinning is done, what we need to do is to provide freeing mechanisms -
// to protect against data that was deleted).
static size_t animdata_filter_dopesheet(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
int filter_mode)
{
Scene *scene = (Scene *)ads->source;
ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
size_t items = 0;
/* check that we do indeed have a scene */
if ((ads->source == NULL) || (GS(ads->source->name) != ID_SCE)) {
printf("Dope Sheet Error: No scene!\n");
if (G.debug & G_DEBUG) {
printf("\tPointer = %p, Name = '%s'\n",
(void *)ads->source,
(ads->source) ? ads->source->name : NULL);
}
return 0;
}
/* augment the filter-flags with settings based on the dopesheet filterflags
* so that some temp settings can get added automagically...
*/
if (ads->filterflag & ADS_FILTER_SELEDIT) {
/* only selected F-Curves should get their keyframes considered for editability */
filter_mode |= ANIMFILTER_SELEDIT;
}
/* Cache files level animations (frame duration and such). */
if (!(ads->filterflag2 & ADS_FILTER_NOCACHEFILES) && !(ads->filterflag & ADS_FILTER_ONLYSEL)) {
CacheFile *cache_file = ac->bmain->cachefiles.first;
for (; cache_file; cache_file = cache_file->id.next) {
items += animdata_filter_ds_cachefile(ac, anim_data, ads, cache_file, filter_mode);
}
}
/* movie clip's animation */
if (!(ads->filterflag2 & ADS_FILTER_NOMOVIECLIPS) && !(ads->filterflag & ADS_FILTER_ONLYSEL)) {
items += animdata_filter_dopesheet_movieclips(ac, anim_data, ads, filter_mode);
}
/* Scene-linked animation - e.g. world, compositing nodes, scene anim
* (including sequencer currently). */
items += animdata_filter_dopesheet_scene(ac, anim_data, ads, scene, filter_mode);
/* If filtering for channel drawing, we want the objects in alphabetical order,
* to make it easier to predict where items are in the hierarchy
* - This order only really matters
* if we need to show all channels in the list (e.g. for drawing).
* (XXX: What about lingering "active" flags? The order may now become unpredictable)
* - Don't do this if this behavior has been turned off (i.e. due to it being too slow)
* - Don't do this if there's just a single object
*/
if ((filter_mode & ANIMFILTER_LIST_CHANNELS) && !(ads->flag & ADS_FLAG_NO_DB_SORT) &&
(view_layer->object_bases.first != view_layer->object_bases.last)) {
/* Filter list of bases (i.e. objects), sort them, then add their contents normally... */
// TODO: Cache the old sorted order - if the set of bases hasn't changed, don't re-sort...
Base **sorted_bases;
size_t num_bases;
sorted_bases = animdata_filter_ds_sorted_bases(ads, view_layer, filter_mode, &num_bases);
if (sorted_bases) {
/* Add the necessary channels for these bases... */
for (size_t i = 0; i < num_bases; i++) {
items += animdata_filter_dopesheet_ob(ac, anim_data, ads, sorted_bases[i], filter_mode);
}
// TODO: store something to validate whether any changes are needed?
/* free temporary data */
MEM_freeN(sorted_bases);
}
}
else {
/* Filter and add contents of each base (i.e. object) without them sorting first
* NOTE: This saves performance in cases where order doesn't matter
*/
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (animdata_filter_base_is_ok(ads, base, filter_mode)) {
/* since we're still here, this object should be usable */
items += animdata_filter_dopesheet_ob(ac, anim_data, ads, base, filter_mode);
}
}
}
/* return the number of items in the list */
return items;
}
/* Summary track for DopeSheet/Action Editor
* - return code is whether the summary lets the other channels get drawn
*/
static short animdata_filter_dopesheet_summary(bAnimContext *ac,
ListBase *anim_data,
int filter_mode,
size_t *items)
{
bDopeSheet *ads = NULL;
/* get the DopeSheet information to use
* - we should only need to deal with the DopeSheet/Action Editor,
* since all the other Animation Editors won't have this concept
* being applicable.
*/
if ((ac && ac->sl) && (ac->spacetype == SPACE_ACTION)) {
SpaceAction *saction = (SpaceAction *)ac->sl;
ads = &saction->ads;
}
else {
/* invalid space type - skip this summary channels */
return 1;
}
/* dopesheet summary
* - only for drawing and/or selecting keyframes in channels, but not for real editing
* - only useful for DopeSheet/Action/etc. editors where it is actually useful
*/
if ((filter_mode & ANIMFILTER_LIST_CHANNELS) && (ads->filterflag & ADS_FILTER_SUMMARY)) {
bAnimListElem *ale = make_new_animlistelem(ac, ANIMTYPE_SUMMARY, NULL, NULL);
if (ale) {
BLI_addtail(anim_data, ale);
(*items)++;
}
/* If summary is collapsed, don't show other channels beneath this - this check is put inside
* the summary check so that it doesn't interfere with normal operation.
*/
if (ads->flag & ADS_FLAG_SUMMARY_COLLAPSED) {
return 0;
}
}
/* the other channels beneath this can be shown */
return 1;
}
/* ......................... */
/* filter data associated with a channel - usually for handling summary-channels in DopeSheet */
static size_t animdata_filter_animchan(bAnimContext *ac,
ListBase *anim_data,
bDopeSheet *ads,
bAnimListElem *channel,
int filter_mode)
{
size_t items = 0;
/* data to filter depends on channel type */
/* NOTE: only common channel-types have been handled for now. More can be added as necessary */
switch (channel->type) {
case ANIMTYPE_SUMMARY:
items += animdata_filter_dopesheet(ac, anim_data, ads, filter_mode);
break;
case ANIMTYPE_SCENE:
items += animdata_filter_dopesheet_scene(ac, anim_data, ads, channel->data, filter_mode);
break;
case ANIMTYPE_OBJECT:
items += animdata_filter_dopesheet_ob(ac, anim_data, ads, channel->data, filter_mode);
break;
case ANIMTYPE_DSCACHEFILE:
items += animdata_filter_ds_cachefile(ac, anim_data, ads, channel->data, filter_mode);
break;
case ANIMTYPE_ANIMDATA:
items += animfilter_block_data(ac, anim_data, ads, channel->id, filter_mode);
break;
default:
printf("ERROR: Unsupported channel type (%d) in animdata_filter_animchan()\n",
channel->type);
break;
}
return items;
}
/* ----------- Cleanup API --------------- */
/* Remove entries with invalid types in animation channel list */
static size_t animdata_filter_remove_invalid(ListBase *anim_data)
{
bAnimListElem *ale, *next;
size_t items = 0;
/* only keep entries with valid types */
for (ale = anim_data->first; ale; ale = next) {
next = ale->next;
if (ale->type == ANIMTYPE_NONE) {
BLI_freelinkN(anim_data, ale);
}
else {
items++;
}
}
return items;
}
/* Remove duplicate entries in animation channel list */
static size_t animdata_filter_remove_duplis(ListBase *anim_data)
{
bAnimListElem *ale, *next;
GSet *gs;
size_t items = 0;
/* build new hashtable to efficiently store and retrieve which entries have been
* encountered already while searching
*/
gs = BLI_gset_ptr_new(__func__);
/* loop through items, removing them from the list if a similar item occurs already */
for (ale = anim_data->first; ale; ale = next) {
next = ale->next;
/* check if hash has any record of an entry like this
* - just use ale->data for now, though it would be nicer to involve
* ale->type in combination too to capture corner cases
* (where same data performs differently)
*/
if (BLI_gset_add(gs, ale->data)) {
/* this entry is 'unique' and can be kept */
items++;
}
else {
/* this entry isn't needed anymore */
BLI_freelinkN(anim_data, ale);
}
}
/* free the hash... */
BLI_gset_free(gs, NULL);
/* return the number of items still in the list */
return items;
}
/* ----------- Public API --------------- */
/**
* This function filters the active data source to leave only animation channels suitable for
* usage by the caller. It will return the length of the list
*
* \param anim_data: Is a pointer to a #ListBase,
* to which the filtered animation channels will be placed for use.
* \param filter_mode: how should the data be filtered - bit-mapping accessed flags.
*/
size_t ANIM_animdata_filter(bAnimContext *ac,
ListBase *anim_data,
eAnimFilter_Flags filter_mode,
void *data,
eAnimCont_Types datatype)
{
size_t items = 0;
/* only filter data if there's somewhere to put it */
if (data && anim_data) {
/* firstly filter the data */
switch (datatype) {
/* Action-Editing Modes */
case ANIMCONT_ACTION: /* 'Action Editor' */
{
Object *obact = ac->obact;
SpaceAction *saction = (SpaceAction *)ac->sl;
bDopeSheet *ads = (saction) ? &saction->ads : NULL;
/* specially check for AnimData filter... [#36687] */
if (UNLIKELY(filter_mode & ANIMFILTER_ANIMDATA)) {
/* all channels here are within the same AnimData block, hence this special case */
if (LIKELY(obact->adt)) {
ANIMCHANNEL_NEW_CHANNEL(obact->adt, ANIMTYPE_ANIMDATA, (ID *)obact, NULL);
}
}
else {
/* The check for the DopeSheet summary is included here
* since the summary works here too. */
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items += animfilter_action(ac, anim_data, ads, data, filter_mode, (ID *)obact);
}
}
break;
}
case ANIMCONT_SHAPEKEY: /* 'ShapeKey Editor' */
{
Key *key = (Key *)data;
/* specially check for AnimData filter... [#36687] */
if (UNLIKELY(filter_mode & ANIMFILTER_ANIMDATA)) {
/* all channels here are within the same AnimData block, hence this special case */
if (LIKELY(key->adt)) {
ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, (ID *)key, NULL);
}
}
else {
/* The check for the DopeSheet summary is included here
* since the summary works here too. */
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items = animdata_filter_shapekey(ac, anim_data, key, filter_mode);
}
}
break;
}
/* Modes for Specialty Data Types (i.e. not keyframes) */
case ANIMCONT_GPENCIL: {
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items = animdata_filter_gpencil(ac, anim_data, data, filter_mode);
}
break;
}
case ANIMCONT_MASK: {
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items = animdata_filter_mask(ac->bmain, anim_data, data, filter_mode);
}
break;
}
/* DopeSheet Based Modes */
case ANIMCONT_DOPESHEET: /* 'DopeSheet Editor' */
{
/* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
}
break;
}
case ANIMCONT_FCURVES: /* Graph Editor -> F-Curves/Animation Editing */
case ANIMCONT_DRIVERS: /* Graph Editor -> Drivers Editing */
case ANIMCONT_NLA: /* NLA Editor */
{
/* all of these editors use the basic DopeSheet data for filtering options,
* but don't have all the same features */
items = animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
break;
}
/* Timeline Mode - Basically the same as dopesheet,
* except we only have the summary for now */
case ANIMCONT_TIMELINE: {
/* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */
if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items)) {
items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
}
break;
}
/* Special/Internal Use */
case ANIMCONT_CHANNEL: /* animation channel */
{
bDopeSheet *ads = ac->ads;
/* based on the channel type, filter relevant data for this */
items = animdata_filter_animchan(ac, anim_data, ads, data, filter_mode);
break;
}
/* unhandled */
default: {
printf("ANIM_animdata_filter() - Invalid datatype argument %u\n", datatype);
break;
}
}
/* remove any 'weedy' entries */
items = animdata_filter_remove_invalid(anim_data);
/* remove duplicates (if required) */
if (filter_mode & ANIMFILTER_NODUPLIS) {
items = animdata_filter_remove_duplis(anim_data);
}
}
/* return the number of items in the list */
return items;
}
/* ************************************************************ */
|