Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3580x 3578x 3578x 271x 3578x 3578x 3578x 26x 3578x 3578x 3578x 3578x 2x 2x 3578x 3578x 1019x 1x 1019x 2559x 2470x 89x 3578x 3578x 3578x 3578x 3578x 3578x 99x 99x 3479x 1891x 1891x 8x 8x 1891x 1x 1x 1x 1x 1890x 1890x 1890x 1588x 1588x 1588x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3x 3x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 3578x 1x 1x 192328x 35851x 4204x 5978x 26590x 44975x 7x 28x 28x 20344x 32341x 17328x 19940x 27834x 44x 4x 1x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 3470x 3470x 3470x 3470x 3470x 3470x 17212x 20682x 20682x 20682x 9873x 10809x 10809x 10809x 10540x 269x 269x 269x 269x 269x 1x 1x 53344x 53344x 53344x 53344x 53344x 23614x 29730x 29730x 29730x 29730x 29730x 27x 27x 12x 27x 27x 29703x 29703x 29703x 29703x 29643x 29643x 29643x 29643x 29730x 29730x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 9773x 9773x 20682x 20682x 20682x 20682x 20682x 1x 24855x 24855x 4173x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 20682x 1x 20855x 26x 26x 4x 4x 1548x 1543x 5x 5x 5x 5x 1694x 3203x 1x 1796x 1796x 102x 1694x 102x 102x 102x 99x 99x 99x 102x 102x 2x 100x 100x 100x 100x 3x 97x 97x 1535x 1535x 1535x 1535x 1535x 72x 72x 10x 62x 59x 59x 59x 3x 3x 1463x 3x 3x 1460x 1460x 1460x 1454x 1454x 1454x 3x 1454x 1454x 1454x 6x 6x 6x 6x 1694x 1694x 1694x 6x 1694x 1694x 1694x 1694x 1694x 1694x 159x 159x 1535x 1460x 1455x 1455x 1455x 46x 46x 1455x 39x 39x 1455x 1455x 1455x 1214x 241x 1454x 1454x 110x 110x 110x 1344x 1298x 1454x 1454x 26x 1454x 1x 2x 2x 1x 76x 76x 76x 76x 76x 76x 76x 76x 76x 76x 76x 76x 1x 62077x 21x 21x 21x 62077x 1026x 4x 4x 4x 1026x 1x 20713x 20713x 20713x 20713x 20713x 104x 104x 104x 12x 20701x 20701x 20701x 1x 7324x 6278x 1046x 20x 1026x 1026x 1026x 1026x 1026x 13x 13x 13x 1x 1025x 1025x 1025x 1x 20682x 20682x 1x 1x 20682x 20682x 20682x 20682x 1x 20682x 20682x 1x 1x 1x 1x 1x 1x 1x 1700x 1700x 1700x 1700x 1700x 1700x 17x 17x 1683x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 2532x 80x 80x 2452x 2452x 7x 7x 7x 7x 7x 2445x 194x 194x 194x 194x 194x 194x 194x 7x 7x 187x 1x 4474x 4474x 29x 4474x 1x 4474x 1x 4473x 46x 4427x 4427x 1700x 1700x 2x 1700x 2727x 2532x 2532x 2525x 7x 7x 7x 7x 7x 195x 194x 194x 1x 1x 1x 194x 1x 1x 2x 16x 2x 2x 1x 26580x 26580x 26580x 26580x 26580x 26537x 43x 35x 43x 8x 8x 43x 43x 43x 43x 4x 43x 43x 43x 43x 43x 1x 3621x 3621x 3621x 3621x 3604x 3604x 9515x 516x 8999x 8999x 8999x 5x 5x 4x 1x 5x 5x 5x 5x 5x 8994x 1x 8999x 1x 1x 1x 8998x 1x 8999x 2x 2x 2x 8997x 1x 8999x 8999x 8999x 16x 16x 16x 8983x 11x 11x 8999x 28x 28x 8999x 11x 9515x 9515x 22x 19x 19x 19x 3x 3x 9496x 75x 9421x 9421x 1x 1x 9515x 9515x 9515x 68x 9515x 24x 24x 9515x 9515x 9515x 9515x 1x 9515x 9515x 9515x 9515x 9515x 9515x 9514x 9514x 9514x 17750x 17750x 17750x 9514x 9514x 1x 1x 5934x 1548x 1548x 1548x 1548x 1548x 1548x 1461x 1461x 1461x 1461x 5934x 5934x 5934x 5934x 3x 3x 5931x 5931x 4192x 4192x 4192x 6288x 1x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 2096x 1x 13875x 1x 3190x 3190x 3190x 3190x 3190x 3190x | import BoundingSphere from "../Core/BoundingSphere.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Color from "../Core/Color.js";
import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
import CullingVolume from "../Core/CullingVolume.js";
import defined from "../Core/defined.js";
import deprecationWarning from "../Core/deprecationWarning.js";
import destroyObject from "../Core/destroyObject.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import Intersect from "../Core/Intersect.js";
import JulianDate from "../Core/JulianDate.js";
import CesiumMath from "../Core/Math.js";
import Matrix3 from "../Core/Matrix3.js";
import Matrix4 from "../Core/Matrix4.js";
import OrientedBoundingBox from "../Core/OrientedBoundingBox.js";
import OrthographicFrustum from "../Core/OrthographicFrustum.js";
import Rectangle from "../Core/Rectangle.js";
import Request from "../Core/Request.js";
import RequestScheduler from "../Core/RequestScheduler.js";
import RequestState from "../Core/RequestState.js";
import RequestType from "../Core/RequestType.js";
import Resource from "../Core/Resource.js";
import RuntimeError from "../Core/RuntimeError.js";
import Cesium3DContentGroup from "./Cesium3DContentGroup.js";
import Cesium3DTileContentFactory from "./Cesium3DTileContentFactory.js";
import Cesium3DTileContentState from "./Cesium3DTileContentState.js";
import Cesium3DTileContentType from "./Cesium3DTileContentType.js";
import Cesium3DTileOptimizationHint from "./Cesium3DTileOptimizationHint.js";
import Cesium3DTilePass from "./Cesium3DTilePass.js";
import Cesium3DTileRefine from "./Cesium3DTileRefine.js";
import Empty3DTileContent from "./Empty3DTileContent.js";
import findContentMetadata from "./findContentMetadata.js";
import findGroupMetadata from "./findGroupMetadata.js";
import findTileMetadata from "./findTileMetadata.js";
import hasExtension from "./hasExtension.js";
import Multiple3DTileContent from "./Multiple3DTileContent.js";
import BoundingVolumeSemantics from "./BoundingVolumeSemantics.js";
import preprocess3DTileContent from "./preprocess3DTileContent.js";
import SceneMode from "./SceneMode.js";
import TileBoundingRegion from "./TileBoundingRegion.js";
import TileBoundingS2Cell from "./TileBoundingS2Cell.js";
import TileBoundingSphere from "./TileBoundingSphere.js";
import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
import Pass from "../Renderer/Pass.js";
import VerticalExaggeration from "../Core/VerticalExaggeration.js";
/**
* A tile in a {@link Cesium3DTileset}. When a tile is first created, its content is not loaded;
* the content is loaded on-demand when needed based on the view.
* <p>
* Do not construct this directly, instead access tiles through {@link Cesium3DTileset#tileVisible}.
* </p>
*
* @alias Cesium3DTile
* @constructor
* @param {Cesium3DTileset} tileset The tileset
* @param {Resource} baseResource The base resource for the tileset
* @param {object} header The JSON header for the tile
* @param {Cesium3DTile} parent The parent tile of the new tile
*/
function Cesium3DTile(tileset, baseResource, header, parent) {
this._tileset = tileset;
this._header = header;
const hasContentsArray = defined(header.contents);
const hasMultipleContents =
(hasContentsArray && header.contents.length > 1) ||
hasExtension(header, "3DTILES_multiple_contents");
// In the 1.0 schema, content is stored in tile.content instead of tile.contents
const contentHeader =
hasContentsArray && !hasMultipleContents
? header.contents[0]
: header.content;
this._contentHeader = contentHeader;
/**
* The local transform of this tile.
* @type {Matrix4}
*/
this.transform = defined(header.transform)
? Matrix4.unpack(header.transform)
: Matrix4.clone(Matrix4.IDENTITY);
const parentTransform = defined(parent)
? parent.computedTransform
: tileset.modelMatrix;
const computedTransform = Matrix4.multiply(
parentTransform,
this.transform,
new Matrix4(),
);
const parentInitialTransform = defined(parent)
? parent._initialTransform
: Matrix4.IDENTITY;
this._initialTransform = Matrix4.multiply(
parentInitialTransform,
this.transform,
new Matrix4(),
);
/**
* The final computed transform of this tile.
* @type {Matrix4}
* @readonly
*/
this.computedTransform = computedTransform;
/**
* When tile metadata is present (3D Tiles 1.1) or the <code>3DTILES_metadata</code> extension is used,
* this stores a {@link TileMetadata} object for accessing tile metadata.
*
* @type {TileMetadata}
* @readonly
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.metadata = findTileMetadata(tileset, header);
this._verticalExaggeration = 1.0;
this._verticalExaggerationRelativeHeight = 0.0;
// Important: tile metadata must be parsed before this line so that the
// metadata semantics TILE_BOUNDING_BOX, TILE_BOUNDING_REGION, or TILE_BOUNDING_SPHERE
// can override header.boundingVolume (if necessary)
this._boundingVolume = this.createBoundingVolume(
header.boundingVolume,
computedTransform,
);
this._boundingVolume2D = undefined;
let contentBoundingVolume;
if (defined(contentHeader) && defined(contentHeader.boundingVolume)) {
// Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume
// around only the features in the tile. This box is useful for culling for rendering,
// but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e.,
// since it only bounds features in the tile, not the entire tile, children may be
// outside of this box.
contentBoundingVolume = this.createBoundingVolume(
contentHeader.boundingVolume,
computedTransform,
);
}
this._contentBoundingVolume = contentBoundingVolume;
this._contentBoundingVolume2D = undefined;
let viewerRequestVolume;
if (defined(header.viewerRequestVolume)) {
viewerRequestVolume = this.createBoundingVolume(
header.viewerRequestVolume,
computedTransform,
);
}
this._viewerRequestVolume = viewerRequestVolume;
/**
* The error, in meters, introduced if this tile is rendered and its children are not.
* This is used to compute screen space error, i.e., the error measured in pixels.
*
* @type {number}
* @readonly
*/
this.geometricError = header.geometricError;
this._geometricError = header.geometricError;
if (!defined(this._geometricError)) {
this._geometricError = defined(parent)
? parent._geometricError
: tileset._geometricError;
Cesium3DTile._deprecationWarning(
"geometricErrorUndefined",
"Required property geometricError is undefined for this tile. Using parent's geometric error instead.",
);
}
this.updateGeometricErrorScale();
let refine;
if (defined(header.refine)) {
if (header.refine === "replace" || header.refine === "add") {
Cesium3DTile._deprecationWarning(
"lowercase-refine",
`This tile uses a lowercase refine "${
header.refine
}". Instead use "${header.refine.toUpperCase()}".`,
);
}
refine =
header.refine.toUpperCase() === "REPLACE"
? Cesium3DTileRefine.REPLACE
: Cesium3DTileRefine.ADD;
} else if (defined(parent)) {
// Inherit from parent tile if omitted.
refine = parent.refine;
} else {
refine = Cesium3DTileRefine.REPLACE;
}
/**
* Specifies the type of refinement that is used when traversing this tile for rendering.
*
* @type {Cesium3DTileRefine}
* @readonly
* @private
*/
this.refine = refine;
/**
* Gets the tile's children.
*
* @type {Cesium3DTile[]}
* @readonly
*/
this.children = [];
/**
* This tile's parent or <code>undefined</code> if this tile is the root.
* <p>
* When a tile's content points to an external tileset JSON file, the external tileset's
* root tile's parent is not <code>undefined</code>; instead, the parent references
* the tile (with its content pointing to an external tileset JSON file) as if the two tilesets were merged.
* </p>
*
* @type {Cesium3DTile}
* @readonly
*/
this.parent = parent;
let content;
let hasEmptyContent = false;
let contentState;
let contentResource;
let serverKey;
baseResource = Resource.createIfNeeded(baseResource);
if (hasMultipleContents) {
contentState = Cesium3DTileContentState.UNLOADED;
// Each content may have its own URI, but they all need to be resolved
// relative to the tileset, so the base resource is used.
contentResource = baseResource.clone();
} else if (defined(contentHeader)) {
let contentHeaderUri = contentHeader.uri;
if (defined(contentHeader.url)) {
Cesium3DTile._deprecationWarning(
"contentUrl",
'This tileset JSON uses the "content.url" property which has been deprecated. Use "content.uri" instead.',
);
contentHeaderUri = contentHeader.url;
}
if (contentHeaderUri === "") {
Cesium3DTile._deprecationWarning(
"contentUriEmpty",
"content.uri property is an empty string, which creates a circular dependency, making this tileset invalid. Omit the content property instead",
);
content = new Empty3DTileContent(tileset, this);
hasEmptyContent = true;
contentState = Cesium3DTileContentState.READY;
} else {
contentState = Cesium3DTileContentState.UNLOADED;
contentResource = baseResource.getDerivedResource({
url: contentHeaderUri,
});
serverKey = RequestScheduler.getServerKey(
contentResource.getUrlComponent(),
);
}
} else {
content = new Empty3DTileContent(tileset, this);
hasEmptyContent = true;
contentState = Cesium3DTileContentState.READY;
}
this._content = content;
this._contentResource = contentResource;
this._contentState = contentState;
this._expiredContent = undefined;
this._serverKey = serverKey;
/**
* When <code>true</code>, the tile has no content.
*
* @type {boolean}
* @readonly
*
* @private
*/
this.hasEmptyContent = hasEmptyContent;
/**
* When <code>true</code>, the tile's content points to an external tileset.
* <p>
* This is <code>false</code> until the tile's content is loaded.
* </p>
*
* @type {boolean}
* @readonly
*
* @private
*/
this.hasTilesetContent = false;
/**
* When <code>true</code>, the tile's content is an implicit tileset.
* <p>
* This is <code>false</code> until the tile's implicit content is loaded.
* </p>
*
* @type {boolean}
* @readonly
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.hasImplicitContent = false;
/**
* Determines whether the tile has renderable content.
*
* The loading starts with the assumption that the tile does have
* renderable content, if the content is not empty.<br>
* <br>
* This turns <code>false</code> only when the tile content is loaded
* and turns out to be a single content that points to an external
* tileset or implicit content
* </p>
*
* @type {boolean}
* @readonly
*
* @private
*/
this.hasRenderableContent = !hasEmptyContent;
/**
* When <code>true</code>, the tile contains content metadata from implicit tiling. This flag is set
* for tiles transcoded by <code>Implicit3DTileContent</code>.
* <p>
* This is <code>false</code> until the tile's content is loaded.
* </p>
*
* @type {boolean}
* @readonly
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.hasImplicitContentMetadata = false;
/**
* When <code>true</code>, the tile has multiple contents, either in the tile JSON (3D Tiles 1.1)
* or via the <code>3DTILES_multiple_contents</code> extension.
*
* @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_multiple_contents|3DTILES_multiple_contents extension}
*
* @type {boolean}
* @readonly
*
* @private
*/
this.hasMultipleContents = hasMultipleContents;
/**
* The node in the tileset's LRU cache, used to determine when to unload a tile's content.
*
* See {@link Cesium3DTilesetCache}
*
* @type {DoublyLinkedListNode}
* @readonly
*
* @private
*/
this.cacheNode = undefined;
const expire = header.expire;
let expireDuration;
let expireDate;
if (defined(expire)) {
expireDuration = expire.duration;
Iif (defined(expire.date)) {
expireDate = JulianDate.fromIso8601(expire.date);
}
}
/**
* The time in seconds after the tile's content is ready when the content expires and new content is requested.
*
* @type {number}
*/
this.expireDuration = expireDuration;
/**
* The date when the content expires and new content is requested.
*
* @type {JulianDate}
*/
this.expireDate = expireDate;
/**
* The time when a style was last applied to this tile.
*
* @type {number}
*
* @private
*/
this.lastStyleTime = 0.0;
/**
* Marks whether the tile's children bounds are fully contained within the tile's bounds
*
* @type {Cesium3DTileOptimizationHint}
*
* @private
*/
this._optimChildrenWithinParent = Cesium3DTileOptimizationHint.NOT_COMPUTED;
/**
* Tracks if the tile's relationship with a ClippingPlaneCollection has changed with regards
* to the ClippingPlaneCollection's state.
*
* @type {boolean}
*
* @private
*/
this.clippingPlanesDirty = false;
/**
* Tracks if the tile's relationship with a ClippingPolygonCollection has changed with regards
* to the ClippingPolygonCollection's state.
*
* @type {boolean}
*
* @private
*/
this.clippingPolygonsDirty = false;
/**
* Tracks if the tile's request should be deferred until all non-deferred
* tiles load.
*
* @type {boolean}
*
* @private
*/
this.priorityDeferred = false;
/**
* For implicit tiling, an ImplicitTileset object will be attached to a
* placeholder tile with either implicit tiling in the JSON (3D Tiles 1.1)
* or the <code>3DTILES_implicit_tiling</code> extension.
* This way the {@link Implicit3DTileContent} can access the tile later once the content is fetched.
*
* @type {ImplicitTileset|undefined}
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.implicitTileset = undefined;
/**
* For implicit tiling, the (level, x, y, [z]) coordinates within the
* implicit tileset are stored in the tile.
*
* @type {ImplicitTileCoordinates|undefined}
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.implicitCoordinates = undefined;
/**
* For implicit tiling, each transcoded tile will hold a weak reference to
* the {@link ImplicitSubtree}.
*
* @type {ImplicitSubtree|undefined}
*
* @private
* @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
*/
this.implicitSubtree = undefined;
// Members that are updated every frame for tree traversal and rendering optimizations:
this._distanceToCamera = 0.0;
this._centerZDepth = 0.0;
this._screenSpaceError = 0.0;
this._screenSpaceErrorProgressiveResolution = 0.0; // The screen space error at a given screen height of tileset.progressiveResolutionHeightFraction * screenHeight
this._visibilityPlaneMask = 0;
this._visible = false;
this._inRequestVolume = false;
this._finalResolution = true;
this._depth = 0;
this._stackLength = 0;
this._selectionDepth = 0;
this._updatedVisibilityFrame = 0;
this._touchedFrame = 0;
this._visitedFrame = 0;
this._selectedFrame = 0;
this._wasSelectedLastFrame = false;
this._requestedFrame = 0;
this._ancestorWithContent = undefined;
this._ancestorWithContentAvailable = undefined;
this._refines = false;
this._shouldSelect = false;
this._isClipped = true;
this._isClippedByPolygon = false;
this._clippingPlanesState = 0; // encapsulates (_isClipped, clippingPlanes.enabled) and number/function
this._clippingPolygonsState = 0; // encapsulates (_isClipped, clippingPolygons.enabled) and number/function
this._debugBoundingVolume = undefined;
this._debugContentBoundingVolume = undefined;
this._debugViewerRequestVolume = undefined;
this._debugColor = Color.fromRandom({ alpha: 1.0 });
this._debugColorizeTiles = false;
this._priority = 0.0; // The priority used for request sorting
this._priorityHolder = this; // Reference to the ancestor up the tree that holds the _foveatedFactor and _distanceToCamera for all tiles in the refinement chain.
this._priorityProgressiveResolution = false;
this._priorityProgressiveResolutionScreenSpaceErrorLeaf = false;
this._priorityReverseScreenSpaceError = 0.0;
this._foveatedFactor = 0.0;
this._wasMinPriorityChild = false; // Needed for knowing when to continue a refinement chain. Gets reset in updateTile in traversal and gets set in updateAndPushChildren in traversal.
this._loadTimestamp = new JulianDate();
this._commandsLength = 0;
this._color = undefined;
this._colorDirty = false;
this._request = undefined;
}
// This can be overridden for testing purposes
Cesium3DTile._deprecationWarning = deprecationWarning;
Object.defineProperties(Cesium3DTile.prototype, {
/**
* The tileset containing this tile.
*
* @memberof Cesium3DTile.prototype
*
* @type {Cesium3DTileset}
* @readonly
*/
tileset: {
get: function () {
return this._tileset;
},
},
/**
* The tile's content. This represents the actual tile's payload,
* not the content's metadata in the tileset JSON file.
*
* @memberof Cesium3DTile.prototype
*
* @type {Cesium3DTileContent}
* @readonly
*/
content: {
get: function () {
return this._content;
},
},
/**
* Get the tile's bounding volume.
*
* @memberof Cesium3DTile.prototype
*
* @type {TileBoundingVolume}
* @readonly
* @private
*/
boundingVolume: {
get: function () {
return this._boundingVolume;
},
},
/**
* Get the bounding volume of the tile's contents. This defaults to the
* tile's bounding volume when the content's bounding volume is
* <code>undefined</code>.
*
* @memberof Cesium3DTile.prototype
*
* @type {TileBoundingVolume}
* @readonly
* @private
*/
contentBoundingVolume: {
get: function () {
return this._contentBoundingVolume ?? this._boundingVolume;
},
},
/**
* Get the bounding sphere derived from the tile's bounding volume.
*
* @memberof Cesium3DTile.prototype
*
* @type {BoundingSphere}
* @readonly
*/
boundingSphere: {
get: function () {
return this._boundingVolume.boundingSphere;
},
},
/**
* Determines if the tile is visible within the current field of view
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
isVisible: {
get: function () {
return this._visible && this._inRequestVolume;
},
},
/**
* Returns the <code>extras</code> property in the tileset JSON for this tile, which contains application specific metadata.
* Returns <code>undefined</code> if <code>extras</code> does not exist.
*
* @memberof Cesium3DTile.prototype
*
* @type {object}
* @readonly
* @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}
*/
extras: {
get: function () {
return this._header.extras;
},
},
/**
* Gets or sets the tile's highlight color.
*
* @memberof Cesium3DTile.prototype
*
* @type {Color}
*
* @default {@link Color.WHITE}
*
* @private
*/
color: {
get: function () {
if (!defined(this._color)) {
this._color = new Color();
}
return Color.clone(this._color);
},
set: function (value) {
this._color = Color.clone(value, this._color);
this._colorDirty = true;
},
},
/**
* Determines if the tile has available content to render. <code>true</code> if the tile's
* content is ready or if it has expired content that renders while new content loads; otherwise,
* <code>false</code>.
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
contentAvailable: {
get: function () {
return (
(this.contentReady && this.hasRenderableContent) ||
(defined(this._expiredContent) && !this.contentFailed)
);
},
},
/**
* Determines if the tile's content is ready. This is automatically <code>true</code> for
* tile's with empty content.
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
contentReady: {
get: function () {
return this._contentState === Cesium3DTileContentState.READY;
},
},
/**
* Determines if the tile's content has not be requested. <code>true</code> if tile's
* content has not be requested; otherwise, <code>false</code>.
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
contentUnloaded: {
get: function () {
return this._contentState === Cesium3DTileContentState.UNLOADED;
},
},
/**
* Determines if the tile has renderable content which is unloaded
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
hasUnloadedRenderableContent: {
get: function () {
return this.hasRenderableContent && this.contentUnloaded;
},
},
/**
* Determines if the tile's content is expired. <code>true</code> if tile's
* content is expired; otherwise, <code>false</code>.
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
contentExpired: {
get: function () {
return this._contentState === Cesium3DTileContentState.EXPIRED;
},
},
/**
* Determines if the tile's content failed to load. <code>true</code> if the tile's
* content failed to load; otherwise, <code>false</code>.
*
* @memberof Cesium3DTile.prototype
*
* @type {boolean}
* @readonly
*
* @private
*/
contentFailed: {
get: function () {
return this._contentState === Cesium3DTileContentState.FAILED;
},
},
/**
* Returns the number of draw commands used by this tile.
*
* @readonly
*
* @private
*/
commandsLength: {
get: function () {
return this._commandsLength;
},
},
});
const scratchCartesian = new Cartesian3();
/**
* @private
* @param {Cesium3DTile} tile
* @param {FrameState} frameState
* @returns {boolean}
*/
function isPriorityDeferred(tile, frameState) {
const { tileset, boundingSphere } = tile;
const { radius, center } = boundingSphere;
const { camera } = frameState;
// If closest point on line is inside the sphere then set foveatedFactor to 0.
// Otherwise, the dot product is with the line from camera to the point on the sphere that is closest to the line.
const scaledCameraDirection = Cartesian3.multiplyByScalar(
camera.directionWC,
tile._centerZDepth,
scratchCartesian,
);
const closestPointOnLine = Cartesian3.add(
camera.positionWC,
scaledCameraDirection,
scratchCartesian,
);
// The distance from the camera's view direction to the tile.
const toLine = Cartesian3.subtract(
closestPointOnLine,
center,
scratchCartesian,
);
const distanceToCenterLine = Cartesian3.magnitude(toLine);
const notTouchingSphere = distanceToCenterLine > radius;
// If camera's direction vector is inside the bounding sphere then consider
// this tile right along the line of sight and set _foveatedFactor to 0.
// Otherwise,_foveatedFactor is one minus the dot product of the camera's direction
// and the vector between the camera and the point on the bounding sphere closest to the view line.
if (notTouchingSphere) {
const toLineNormalized = Cartesian3.normalize(toLine, scratchCartesian);
const scaledToLine = Cartesian3.multiplyByScalar(
toLineNormalized,
radius,
scratchCartesian,
);
const closestOnSphere = Cartesian3.add(
center,
scaledToLine,
scratchCartesian,
);
const toClosestOnSphere = Cartesian3.subtract(
closestOnSphere,
camera.positionWC,
scratchCartesian,
);
const toClosestOnSphereNormalize = Cartesian3.normalize(
toClosestOnSphere,
scratchCartesian,
);
tile._foveatedFactor =
1.0 -
Math.abs(Cartesian3.dot(camera.directionWC, toClosestOnSphereNormalize));
} else {
tile._foveatedFactor = 0.0;
}
// Skip this feature if: non-skipLevelOfDetail and replace refine, if the foveated settings are turned off, if tile is progressive resolution and replace refine and skipLevelOfDetail (will help get rid of ancestor artifacts faster)
// Or if the tile is a preload of any kind
const replace = tile.refine === Cesium3DTileRefine.REPLACE;
const skipLevelOfDetail = tileset.isSkippingLevelOfDetail;
if (
(replace && !skipLevelOfDetail) ||
!tileset.foveatedScreenSpaceError ||
tileset.foveatedConeSize === 1.0 ||
(tile._priorityProgressiveResolution && replace && skipLevelOfDetail) ||
tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ||
tileset._pass === Cesium3DTilePass.PRELOAD
) {
return false;
}
const maximumFovatedFactor = 1.0 - Math.cos(camera.frustum.fov * 0.5); // 0.14 for fov = 60. NOTE very hard to defer vertically foveated tiles since max is based on fovy (which is fov). Lowering the 0.5 to a smaller fraction of the screen height will start to defer vertically foveated tiles.
const foveatedConeFactor = tileset.foveatedConeSize * maximumFovatedFactor;
// If it's inside the user-defined view cone, then it should not be deferred.
if (tile._foveatedFactor <= foveatedConeFactor) {
return false;
}
// Relax SSE based on how big the angle is between the tile and the edge of the foveated cone.
const range = maximumFovatedFactor - foveatedConeFactor;
const normalizedFoveatedFactor = CesiumMath.clamp(
(tile._foveatedFactor - foveatedConeFactor) / range,
0.0,
1.0,
);
const sseRelaxation = tileset.foveatedInterpolationCallback(
tileset.foveatedMinimumScreenSpaceErrorRelaxation,
tileset.memoryAdjustedScreenSpaceError,
normalizedFoveatedFactor,
);
const sse =
tile._screenSpaceError === 0.0 && defined(tile.parent)
? tile.parent._screenSpaceError * 0.5
: tile._screenSpaceError;
return tileset.memoryAdjustedScreenSpaceError - sseRelaxation <= sse;
}
const scratchJulianDate = new JulianDate();
/**
* Get the tile's screen space error.
*
* @private
* @param {FrameState} frameState
* @param {boolean} useParentGeometricError
* @param {number} progressiveResolutionHeightFraction
*/
Cesium3DTile.prototype.getScreenSpaceError = function (
frameState,
useParentGeometricError,
progressiveResolutionHeightFraction,
) {
const tileset = this._tileset;
const heightFraction = progressiveResolutionHeightFraction ?? 1.0;
const parentGeometricError = defined(this.parent)
? this.parent.geometricError
: tileset._scaledGeometricError;
const geometricError = useParentGeometricError
? parentGeometricError
: this.geometricError;
if (geometricError === 0.0) {
// Leaf tiles do not have any error so save the computation
return 0.0;
}
const { camera, context } = frameState;
let frustum = camera.frustum;
const width = context.drawingBufferWidth;
const height = context.drawingBufferHeight * heightFraction;
let error;
if (
frameState.mode === SceneMode.SCENE2D ||
frustum instanceof OrthographicFrustum
) {
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}
const pixelSize =
Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) /
Math.max(width, height);
error = geometricError / pixelSize;
} else {
// Avoid divide by zero when viewer is inside the tile
const distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);
const sseDenominator = frustum.sseDenominator;
error = (geometricError * height) / (distance * sseDenominator);
if (tileset.dynamicScreenSpaceError) {
const density = tileset._dynamicScreenSpaceErrorComputedDensity;
const factor = tileset.dynamicScreenSpaceErrorFactor;
const dynamicError = CesiumMath.fog(distance, density) * factor;
error -= dynamicError;
}
}
error /= frameState.pixelRatio;
return error;
};
/**
* @private
* @param {Cesium3DTileset} tileset
* @param {Cesium3DTile} tile
* @returns {boolean}
*/
function isPriorityProgressiveResolution(tileset, tile) {
Iif (
tileset.progressiveResolutionHeightFraction <= 0.0 ||
tileset.progressiveResolutionHeightFraction > 0.5
) {
return false;
}
const maximumScreenSpaceError = tileset.memoryAdjustedScreenSpaceError;
let isProgressiveResolutionTile =
tile._screenSpaceErrorProgressiveResolution > maximumScreenSpaceError; // Mark non-SSE leaves
tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = false; // Needed for skipLOD
const parent = tile.parent;
const tilePasses =
tile._screenSpaceErrorProgressiveResolution <= maximumScreenSpaceError;
const parentFails =
defined(parent) &&
parent._screenSpaceErrorProgressiveResolution > maximumScreenSpaceError;
if (tilePasses && parentFails) {
// A progressive resolution SSE leaf, promote its priority as well
tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = true;
isProgressiveResolutionTile = true;
}
return isProgressiveResolutionTile;
}
/**
* @private
* @param {Cesium3DTileset} tileset
* @param {Cesium3DTile} tile
* @returns {number}
*/
function getPriorityReverseScreenSpaceError(tileset, tile) {
const parent = tile.parent;
const useParentScreenSpaceError =
defined(parent) &&
(!tileset.isSkippingLevelOfDetail ||
tile._screenSpaceError === 0.0 ||
parent.hasTilesetContent ||
parent.hasImplicitContent);
const screenSpaceError = useParentScreenSpaceError
? parent._screenSpaceError
: tile._screenSpaceError;
return tileset.root._screenSpaceError - screenSpaceError;
}
/**
* Update the tile's visibility.
*
* @private
* @param {FrameState} frameState
*/
Cesium3DTile.prototype.updateVisibility = function (frameState) {
const { parent, tileset } = this;
if (this._updatedVisibilityFrame === tileset._updatedVisibilityFrame) {
// The tile has already been updated for this frame
return;
}
const parentTransform = defined(parent)
? parent.computedTransform
: tileset.modelMatrix;
const parentVisibilityPlaneMask = defined(parent)
? parent._visibilityPlaneMask
: CullingVolume.MASK_INDETERMINATE;
this.updateTransform(parentTransform, frameState);
this._distanceToCamera = this.distanceToTile(frameState);
this._centerZDepth = this.distanceToTileCenter(frameState);
this._screenSpaceError = this.getScreenSpaceError(frameState, false);
this._screenSpaceErrorProgressiveResolution = this.getScreenSpaceError(
frameState,
false,
tileset.progressiveResolutionHeightFraction,
);
this._visibilityPlaneMask = this.visibility(
frameState,
parentVisibilityPlaneMask,
); // Use parent's plane mask to speed up visibility test
this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
this._inRequestVolume = this.insideViewerRequestVolume(frameState);
this._priorityReverseScreenSpaceError = getPriorityReverseScreenSpaceError(
tileset,
this,
);
this._priorityProgressiveResolution = isPriorityProgressiveResolution(
tileset,
this,
);
this.priorityDeferred = isPriorityDeferred(this, frameState);
this._updatedVisibilityFrame = tileset._updatedVisibilityFrame;
};
/**
* Update whether the tile has expired.
*
* @private
*/
Cesium3DTile.prototype.updateExpiration = function () {
if (
defined(this.expireDate) &&
this.contentReady &&
!this.hasEmptyContent &&
!this.hasMultipleContents
) {
const now = JulianDate.now(scratchJulianDate);
if (JulianDate.lessThan(this.expireDate, now)) {
this._contentState = Cesium3DTileContentState.EXPIRED;
this._expiredContent = this._content;
}
}
};
/**
* @private
* @param {Cesium3DTile} tile
*/
function updateExpireDate(tile) {
if (!defined(tile.expireDuration)) {
return;
}
const expireDurationDate = JulianDate.now(scratchJulianDate);
JulianDate.addSeconds(
expireDurationDate,
tile.expireDuration,
expireDurationDate,
);
Iif (defined(tile.expireDate)) {
if (JulianDate.lessThan(tile.expireDate, expireDurationDate)) {
JulianDate.clone(expireDurationDate, tile.expireDate);
}
} else {
tile.expireDate = JulianDate.clone(expireDurationDate);
}
}
/**
* @private
* @param {Cesium3DTile} tile
* @returns {Function}
*/
function createPriorityFunction(tile) {
return function () {
return tile._priority;
};
}
/**
* Requests the tile's content.
* <p>
* The request may not be made if the Cesium Request Scheduler can't prioritize it.
* </p>
*
* @return {Promise<Cesium3DTileContent>|undefined} A promise that resolves when the request completes, or undefined if there is no request needed, or the request cannot be scheduled.
* @private
*/
Cesium3DTile.prototype.requestContent = function () {
// empty contents don't require any HTTP requests
Iif (this.hasEmptyContent) {
return;
}
if (this.hasMultipleContents) {
return requestMultipleContents(this);
}
return requestSingleContent(this);
};
/**
* Multiple {@link Cesium3DTileContent}s are allowed within a single tile either through
* the tile JSON (3D Tiles 1.1) or the <code>3DTILES_multiple_contents</code> extension.
* Due to differences in request scheduling, this is handled separately.
* <p>
* This implementation of multiple contents does not
* support tile expiry like requestSingleContent does. If this changes,
* note that the resource.setQueryParameters() details must go inside {@link Multiple3DTileContent} since that is per-request.
* </p>
*
* @private
* @param {Cesium3DTile} tile
* @returns {Promise<Cesium3DTileContent>|Promise<undefined>|undefined} A promise that resolves to the tile content once loaded, or a promise that resolves to undefined if the request was cancelled mid-flight, or undefined if the request cannot be scheduled this frame
*/
function requestMultipleContents(tile) {
let multipleContents = tile._content;
const tileset = tile._tileset;
if (!defined(multipleContents)) {
// Create the content object immediately, it will handle scheduling
// requests for inner contents.
const contentsJson = hasExtension(tile._header, "3DTILES_multiple_contents")
? tile._header.extensions["3DTILES_multiple_contents"]
: tile._header;
multipleContents = new Multiple3DTileContent(
tileset,
tile,
tile._contentResource.clone(),
contentsJson,
);
tile._content = multipleContents;
}
const promise = multipleContents.requestInnerContents();
if (!defined(promise)) {
// Request could not all be scheduled this frame
return;
}
tile._contentState = Cesium3DTileContentState.LOADING;
return promise
.then((content) => {
Iif (tile.isDestroyed()) {
// Tile is unloaded before the content can process
return;
}
// Tile was canceled, try again later
if (!defined(content)) {
return;
}
tile._contentState = Cesium3DTileContentState.PROCESSING;
return multipleContents;
})
.catch((error) => {
if (tile.isDestroyed()) {
// Tile is unloaded before the content can process
return;
}
tile._contentState = Cesium3DTileContentState.FAILED;
throw error;
});
}
async function processArrayBuffer(
tile,
tileset,
request,
expired,
requestPromise,
) {
const previousState = tile._contentState;
tile._contentState = Cesium3DTileContentState.LOADING;
++tileset.statistics.numberOfPendingRequests;
let arrayBuffer;
try {
arrayBuffer = await requestPromise;
} catch (error) {
--tileset.statistics.numberOfPendingRequests;
if (tile.isDestroyed()) {
// Tile is unloaded before the content can process
return;
}
if (request.cancelled || request.state === RequestState.CANCELLED) {
// Cancelled due to low priority - try again later.
tile._contentState = previousState;
++tileset.statistics.numberOfAttemptedRequests;
return;
}
tile._contentState = Cesium3DTileContentState.FAILED;
throw error;
}
if (tile.isDestroyed()) {
--tileset.statistics.numberOfPendingRequests;
// Tile is unloaded before the content can process
return;
}
Iif (request.cancelled || request.state === RequestState.CANCELLED) {
// Cancelled due to low priority - try again later.
tile._contentState = previousState;
--tileset.statistics.numberOfPendingRequests;
++tileset.statistics.numberOfAttemptedRequests;
return;
}
try {
const content = await makeContent(tile, arrayBuffer);
--tileset.statistics.numberOfPendingRequests;
Iif (tile.isDestroyed()) {
// Tile is unloaded before the content can process
return;
}
if (expired) {
tile.expireDate = undefined;
}
tile._content = content;
tile._contentState = Cesium3DTileContentState.PROCESSING;
return content;
} catch (error) {
--tileset.statistics.numberOfPendingRequests;
Iif (tile.isDestroyed()) {
// Tile is unloaded before the content can process
return;
}
tile._contentState = Cesium3DTileContentState.FAILED;
throw error;
}
}
/**
* @private
* @param {Cesium3DTile} tile
* @returns {Promise<Cesium3DTileContent>|Promise<undefined>|undefined} A promise that resolves to the tile content once loaded; a promise that resolves to undefined if the tile was destroyed before processing can happen or the request was cancelled mid-flight; or undefined if the request cannot be scheduled this frame.
*/
function requestSingleContent(tile) {
// it is important to clone here. The fetchArrayBuffer() below uses
// throttling, but other uses of the resources do not.
const resource = tile._contentResource.clone();
const expired = tile.contentExpired;
if (expired) {
// Append a query parameter of the tile expiration date to prevent caching
resource.setQueryParameters({
expired: tile.expireDate.toString(),
});
}
const request = new Request({
throttle: true,
throttleByServer: true,
type: RequestType.TILES3D,
priorityFunction: createPriorityFunction(tile),
serverKey: tile._serverKey,
});
tile._request = request;
resource.request = request;
const tileset = tile._tileset;
const promise = resource.fetchArrayBuffer();
if (!defined(promise)) {
++tileset.statistics.numberOfAttemptedRequests;
return;
}
return processArrayBuffer(tile, tileset, request, expired, promise);
}
/**
* Given a downloaded content payload, construct a {@link Cesium3DTileContent}.
* <p>
* This is only used for single contents.
* </p>
*
* @param {Cesium3DTile} tile The tile
* @param {ArrayBuffer} arrayBuffer The downloaded payload containing data for the content
* @return {Promise<Cesium3DTileContent>} A content object
* @private
*/
async function makeContent(tile, arrayBuffer) {
const preprocessed = preprocess3DTileContent(arrayBuffer);
// Vector and Geometry tile rendering do not support the skip LOD optimization.
const tileset = tile._tileset;
tileset._disableSkipLevelOfDetail =
tileset._disableSkipLevelOfDetail ||
preprocessed.contentType === Cesium3DTileContentType.GEOMETRY ||
preprocessed.contentType === Cesium3DTileContentType.VECTOR;
if (
preprocessed.contentType === Cesium3DTileContentType.IMPLICIT_SUBTREE ||
preprocessed.contentType === Cesium3DTileContentType.IMPLICIT_SUBTREE_JSON
) {
tile.hasImplicitContent = true;
tile.hasRenderableContent = false;
}
if (preprocessed.contentType === Cesium3DTileContentType.EXTERNAL_TILESET) {
tile.hasTilesetContent = true;
tile.hasRenderableContent = false;
}
let content;
const contentFactory = Cesium3DTileContentFactory[preprocessed.contentType];
Iif (tile.isDestroyed()) {
return;
}
if (defined(preprocessed.binaryPayload)) {
content = await Promise.resolve(
contentFactory(
tileset,
tile,
tile._contentResource,
preprocessed.binaryPayload.buffer,
0,
),
);
} else {
// JSON formats
content = await Promise.resolve(
contentFactory(
tileset,
tile,
tile._contentResource,
preprocessed.jsonPayload,
),
);
}
const contentHeader = tile._contentHeader;
if (tile.hasImplicitContentMetadata) {
const subtree = tile.implicitSubtree;
const coordinates = tile.implicitCoordinates;
content.metadata = subtree.getContentMetadataView(coordinates, 0);
} else if (!tile.hasImplicitContent) {
content.metadata = findContentMetadata(tileset, contentHeader);
}
const groupMetadata = findGroupMetadata(tileset, contentHeader);
if (defined(groupMetadata)) {
content.group = new Cesium3DContentGroup({
metadata: groupMetadata,
});
}
return content;
}
/**
* Cancel requests for the tile's contents. This is called when the tile
* goes out of view.
*
* @private
*/
Cesium3DTile.prototype.cancelRequests = function () {
Iif (this.hasMultipleContents) {
this._content.cancelRequests();
} else {
this._request.cancel();
}
};
/**
* Unloads the tile's content.
*
* @private
*/
Cesium3DTile.prototype.unloadContent = function () {
Iif (!this.hasRenderableContent) {
return;
}
this._content = this._content && this._content.destroy();
this._contentState = Cesium3DTileContentState.UNLOADED;
this.lastStyleTime = 0.0;
this.clippingPlanesDirty = this._clippingPlanesState === 0;
this._clippingPlanesState = 0;
this.clippingPolygonsDirty = this._clippingPolygonsState === 0;
this._clippingPolygonsState = 0;
this._debugColorizeTiles = false;
this._debugBoundingVolume =
this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume =
this._debugContentBoundingVolume &&
this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume =
this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
};
const scratchProjectedBoundingSphere = new BoundingSphere();
/**
* @private
* @param {Cesium3DTile} tile
* @param {FrameState} frameState
* @returns {TileBoundingVolume}
*/
function getBoundingVolume(tile, frameState) {
if (
frameState.mode !== SceneMode.SCENE3D &&
!defined(tile._boundingVolume2D)
) {
const boundingSphere = tile._boundingVolume.boundingSphere;
const sphere = BoundingSphere.projectTo2D(
boundingSphere,
frameState.mapProjection,
scratchProjectedBoundingSphere,
);
tile._boundingVolume2D = new TileBoundingSphere(
sphere.center,
sphere.radius,
);
}
return frameState.mode !== SceneMode.SCENE3D
? tile._boundingVolume2D
: tile._boundingVolume;
}
/**
* @private
* @param {Cesium3DTile} tile
* @param {FrameState} frameState
* @returns {TileBoundingVolume}
*/
function getContentBoundingVolume(tile, frameState) {
if (
frameState.mode !== SceneMode.SCENE3D &&
!defined(tile._contentBoundingVolume2D)
) {
const boundingSphere = tile._contentBoundingVolume.boundingSphere;
const sphere = BoundingSphere.projectTo2D(
boundingSphere,
frameState.mapProjection,
scratchProjectedBoundingSphere,
);
tile._contentBoundingVolume2D = new TileBoundingSphere(
sphere.center,
sphere.radius,
);
}
return frameState.mode !== SceneMode.SCENE3D
? tile._contentBoundingVolume2D
: tile._contentBoundingVolume;
}
/**
* Determines whether the tile's bounding volume intersects the culling volume.
*
* @param {FrameState} frameState The frame state.
* @param {number} parentVisibilityPlaneMask The parent's plane mask to speed up the visibility check.
* @returns {number} A plane mask as described above in {@link CullingVolume#computeVisibilityWithPlaneMask}.
*
* @private
*/
Cesium3DTile.prototype.visibility = function (
frameState,
parentVisibilityPlaneMask,
) {
const cullingVolume = frameState.cullingVolume;
const boundingVolume = getBoundingVolume(this, frameState);
const tileset = this._tileset;
const clippingPlanes = tileset.clippingPlanes;
if (defined(clippingPlanes) && clippingPlanes.enabled) {
const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
boundingVolume,
tileset.clippingPlanesOriginMatrix,
);
this._isClipped = intersection !== Intersect.INSIDE;
if (intersection === Intersect.OUTSIDE) {
return CullingVolume.MASK_OUTSIDE;
}
}
const clippingPolygons = tileset.clippingPolygons;
Iif (defined(clippingPolygons) && clippingPolygons.enabled) {
const intersection =
clippingPolygons.computeIntersectionWithBoundingVolume(boundingVolume);
this._isClippedByPolygon = intersection !== Intersect.OUTSIDE;
// Polygon clipping intersections are determined by outer rectangles, therefore we cannot
// preemptively determine if a tile is completely clipped or not here.
}
return cullingVolume.computeVisibilityWithPlaneMask(
boundingVolume,
parentVisibilityPlaneMask,
);
};
/**
* Assuming the tile's bounding volume intersects the culling volume, determines
* whether the tile's content's bounding volume intersects the culling volume.
*
* @param {FrameState} frameState The frame state.
* @returns {Intersect} The result of the intersection: the tile's content is completely outside, completely inside, or intersecting the culling volume.
*
* @private
*/
Cesium3DTile.prototype.contentVisibility = function (frameState) {
// Assumes the tile's bounding volume intersects the culling volume already, so
// just return Intersect.INSIDE if there is no content bounding volume.
if (!defined(this._contentBoundingVolume)) {
return Intersect.INSIDE;
}
if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {
// The tile's bounding volume is completely inside the culling volume so
// the content bounding volume must also be inside.
return Intersect.INSIDE;
}
// PERFORMANCE_IDEA: is it possible to burn less CPU on this test since we know the
// tile's (not the content's) bounding volume intersects the culling volume?
const cullingVolume = frameState.cullingVolume;
const boundingVolume = getContentBoundingVolume(this, frameState);
const tileset = this._tileset;
const clippingPlanes = tileset.clippingPlanes;
if (defined(clippingPlanes) && clippingPlanes.enabled) {
const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
boundingVolume,
tileset.clippingPlanesOriginMatrix,
);
this._isClipped = intersection !== Intersect.INSIDE;
if (intersection === Intersect.OUTSIDE) {
return Intersect.OUTSIDE;
}
}
const clippingPolygons = tileset.clippingPolygons;
Iif (defined(clippingPolygons) && clippingPolygons.enabled) {
const intersection =
clippingPolygons.computeIntersectionWithBoundingVolume(boundingVolume);
this._isClippedByPolygon = intersection !== Intersect.OUTSIDE;
if (intersection === Intersect.INSIDE) {
return Intersect.OUTSIDE;
}
}
return cullingVolume.computeVisibility(boundingVolume);
};
/**
* Computes the (potentially approximate) distance from the closest point of the tile's bounding volume to the camera.
*
* @param {FrameState} frameState The frame state.
* @returns {number} The distance, in meters, or zero if the camera is inside the bounding volume.
*
* @private
*/
Cesium3DTile.prototype.distanceToTile = function (frameState) {
const boundingVolume = getBoundingVolume(this, frameState);
return boundingVolume.distanceToCamera(frameState);
};
const scratchToTileCenter = new Cartesian3();
/**
* Computes the distance from the center of the tile's bounding volume to the camera's plane defined by its position and view direction.
*
* @param {FrameState} frameState The frame state.
* @returns {number} The distance, in meters.
*
* @private
*/
Cesium3DTile.prototype.distanceToTileCenter = function (frameState) {
const tileBoundingVolume = getBoundingVolume(this, frameState);
const boundingVolume = tileBoundingVolume.boundingVolume; // Gets the underlying OrientedBoundingBox or BoundingSphere
const toCenter = Cartesian3.subtract(
boundingVolume.center,
frameState.camera.positionWC,
scratchToTileCenter,
);
return Cartesian3.dot(frameState.camera.directionWC, toCenter);
};
/**
* Checks if the camera is inside the viewer request volume.
*
* @param {FrameState} frameState The frame state.
* @returns {boolean} Whether the camera is inside the volume.
*
* @private
*/
Cesium3DTile.prototype.insideViewerRequestVolume = function (frameState) {
const viewerRequestVolume = this._viewerRequestVolume;
return (
!defined(viewerRequestVolume) ||
viewerRequestVolume.distanceToCamera(frameState) === 0.0
);
};
const scratchMatrix = new Matrix3();
const scratchScale = new Cartesian3();
const scratchHalfAxes = new Matrix3();
const scratchCenter = new Cartesian3();
const scratchRectangle = new Rectangle();
const scratchOrientedBoundingBox = new OrientedBoundingBox();
const scratchTransform = new Matrix4();
/**
* @private
* @param {Array} box An array of 12 numbers that define an oriented bounding box
* @param {Matrix4} transform
* @param {TileBoundingVolume} [result]
* @returns {TileOrientedBoundingBox}
*/
function createBox(box, transform, result) {
let center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter);
let halfAxes = Matrix3.fromArray(box, 3, scratchHalfAxes);
// Find the transformed center and halfAxes
center = Matrix4.multiplyByPoint(transform, center, center);
const rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);
halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
if (defined(result)) {
result.update(center, halfAxes);
return result;
}
return new TileOrientedBoundingBox(center, halfAxes);
}
/**
* @private
* @param {Array} region An array of six numbers that define a bounding geographic region in EPSG:4979 coordinates with the order [west, south, east, north, minimum height, maximum height]
* @param {Matrix4} transform
* @param {Matrix4} initialTransform
* @param {TileOrientedBoundingBox} [result]
* @returns {TileOrientedBoundingBox}
*/
function createBoxFromTransformedRegion(
region,
transform,
initialTransform,
result,
) {
const rectangle = Rectangle.unpack(region, 0, scratchRectangle);
const minimumHeight = region[4];
const maximumHeight = region[5];
const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
rectangle,
minimumHeight,
maximumHeight,
Ellipsoid.WGS84,
scratchOrientedBoundingBox,
);
let center = orientedBoundingBox.center;
let halfAxes = orientedBoundingBox.halfAxes;
// A region bounding volume is not transformed by the transform in the tileset JSON,
// but may be transformed by additional transforms applied in Cesium.
// This is why the transform is calculated as the difference between the initial transform and the current transform.
transform = Matrix4.multiplyTransformation(
transform,
Matrix4.inverseTransformation(initialTransform, scratchTransform),
scratchTransform,
);
center = Matrix4.multiplyByPoint(transform, center, center);
const rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);
halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
Iif (defined(result) && result instanceof TileOrientedBoundingBox) {
result.update(center, halfAxes);
return result;
}
return new TileOrientedBoundingBox(center, halfAxes);
}
/**
* Creates a TileBoundingVolume from the given region and transform
* information.
*
* This may either be a TileBoundingRegion or a TileOrientedBoundingBox.
*
* If the given transform is the initial transform, then this will return
* a TileBoundingRegion. This will either be the given result parameter,
* or a new TileBoundingRegion, if the given result parameter was not
* a TileBoundingRegion.
*
* If the given transform deviates from the initial transform, then this
* will return a TileOrientedBoundingBox that was computed by applying
* the given transform to the given region. This will either be the
* given result parameter, or a new TileOrientedBoundingBox, if the given
* result parameter was not a TileOrientedBoundingBox
*
* @private
* @param {Array} region An array of six numbers that define a bounding
* geographic region in EPSG:4979 coordinates with the order
* [west, south, east, north, minimum height, maximum height]
* @param {Matrix4} transform The current computedTransform of the tile,
* which includes the parent transform (which, in turn, includes the
* modelMatrix of the containing tileset)
* @param {Matrix4} initialTransform The initial transform of the tile,
* before any changes to the modelMatrix of the containing tileset
* @param {TileBoundingVolume} [result] An optional result.
* @returns {TileBoundingVolume} The resulting bounding volume
*/
function createRegion(region, transform, initialTransform, result) {
if (
!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)
) {
Iif (result instanceof TileOrientedBoundingBox) {
return createBoxFromTransformedRegion(
region,
transform,
initialTransform,
result,
);
}
return createBoxFromTransformedRegion(
region,
transform,
initialTransform,
undefined,
);
}
const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
if (result instanceof TileBoundingRegion) {
result.rectangle = Rectangle.clone(rectangleRegion, result.rectangle);
result.minimumHeight = region[4];
result.maximumHeight = region[5];
// The TileBoundingRegion was already constructed with the default
// WGS84 ellipsoid, so keep it consistent when updating.
result.computeBoundingVolumes(Ellipsoid.WGS84);
return result;
}
return new TileBoundingRegion({
rectangle: rectangleRegion,
minimumHeight: region[4],
maximumHeight: region[5],
});
}
/**
* @private
* @param {Array} sphere An array of four numbers that define a bounding sphere
* @param {Matrix4} transform
* @param {TileBoundingVolume} [result]
* @returns {TileBoundingSphere}
*/
function createSphere(sphere, transform, result) {
let center = Cartesian3.fromElements(
sphere[0],
sphere[1],
sphere[2],
scratchCenter,
);
let radius = sphere[3];
// Find the transformed center and radius
center = Matrix4.multiplyByPoint(transform, center, center);
const scale = Matrix4.getScale(transform, scratchScale);
const uniformScale = Cartesian3.maximumComponent(scale);
radius *= uniformScale;
if (defined(result)) {
result.update(center, radius);
return result;
}
return new TileBoundingSphere(center, radius);
}
/**
* Create a bounding volume from the tile's bounding volume header.
*
* @param {object} boundingVolumeHeader The tile's bounding volume header.
* @param {Matrix4} transform The transform to apply to the bounding volume.
* @param {TileBoundingVolume} [result] The object onto which to store the result.
*
* @returns {TileBoundingVolume} The modified result parameter or a new TileBoundingVolume instance if none was provided.
*
* @private
*/
Cesium3DTile.prototype.createBoundingVolume = function (
boundingVolumeHeader,
transform,
result,
) {
// if explicit tile metadata includes TILE_BOUNDING_BOX, TILE_BOUNDING_REGION,
// or TILE_BOUNDING_SPHERE, override tile.boundingVolume.
const tileMetadata = this.metadata;
let metadataBoundingVolumeHeader;
if (defined(tileMetadata)) {
metadataBoundingVolumeHeader =
BoundingVolumeSemantics.parseBoundingVolumeSemantic("TILE", tileMetadata);
}
if (defined(metadataBoundingVolumeHeader)) {
boundingVolumeHeader = metadataBoundingVolumeHeader;
}
if (!defined(boundingVolumeHeader)) {
throw new RuntimeError("boundingVolume must be defined");
}
if (hasExtension(boundingVolumeHeader, "3DTILES_bounding_volume_S2")) {
return new TileBoundingS2Cell(
boundingVolumeHeader.extensions["3DTILES_bounding_volume_S2"],
);
}
const { box, region, sphere } = boundingVolumeHeader;
if (defined(box)) {
const tileOrientedBoundingBox = createBox(box, transform, result);
if (this._verticalExaggeration !== 1.0) {
exaggerateBoundingBox(
tileOrientedBoundingBox,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
);
}
return tileOrientedBoundingBox;
}
if (defined(region)) {
const tileBoundingVolume = createRegion(
region,
transform,
this._initialTransform,
result,
);
if (this._verticalExaggeration === 1.0) {
return tileBoundingVolume;
}
Iif (tileBoundingVolume instanceof TileOrientedBoundingBox) {
exaggerateBoundingBox(
tileBoundingVolume,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
);
} else {
tileBoundingVolume.minimumHeight = VerticalExaggeration.getHeight(
tileBoundingVolume.minimumHeight,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
);
tileBoundingVolume.maximumHeight = VerticalExaggeration.getHeight(
tileBoundingVolume.maximumHeight,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
);
tileBoundingVolume.computeBoundingVolumes(Ellipsoid.WGS84);
}
return tileBoundingVolume;
}
if (defined(sphere)) {
const tileBoundingSphere = createSphere(sphere, transform, result);
if (this._verticalExaggeration !== 1.0) {
const exaggeratedCenter = VerticalExaggeration.getPosition(
tileBoundingSphere.center,
Ellipsoid.WGS84,
this._verticalExaggeration,
this._verticalExaggerationRelativeHeight,
scratchCenter,
);
const exaggeratedRadius =
tileBoundingSphere.radius * this._verticalExaggeration;
tileBoundingSphere.update(exaggeratedCenter, exaggeratedRadius);
}
return tileBoundingSphere;
}
throw new RuntimeError(
"boundingVolume must contain a sphere, region, or box",
);
};
const scratchExaggeratedCorners = Cartesian3.unpackArray(
new Array(8 * 3).fill(0),
);
/**
* Exaggerates the bounding box of a tile based on the provided exaggeration factors.
*
* @private
* @param {TileOrientedBoundingBox} tileOrientedBoundingBox - The oriented bounding box of the tile.
* @param {number} exaggeration - The exaggeration factor to apply to the tile's bounding box.
* @param {number} exaggerationRelativeHeight - The height relative to which exaggeration will be applied.
*/
function exaggerateBoundingBox(
tileOrientedBoundingBox,
exaggeration,
exaggerationRelativeHeight,
) {
const exaggeratedCorners = tileOrientedBoundingBox.boundingVolume
.computeCorners(scratchExaggeratedCorners)
.map((corner) =>
VerticalExaggeration.getPosition(
corner,
Ellipsoid.WGS84,
exaggeration,
exaggerationRelativeHeight,
corner,
),
);
const exaggeratedBox = OrientedBoundingBox.fromPoints(
exaggeratedCorners,
scratchOrientedBoundingBox,
);
tileOrientedBoundingBox.update(
exaggeratedBox.center,
exaggeratedBox.halfAxes,
);
}
/**
* Update the tile's transform. The transform is applied to the tile's bounding volumes.
*
* @private
* @param {Matrix4} parentTransform
* @param {FrameState} [frameState]
*/
Cesium3DTile.prototype.updateTransform = function (
parentTransform,
frameState,
) {
parentTransform = parentTransform ?? Matrix4.IDENTITY;
const computedTransform = Matrix4.multiplyTransformation(
parentTransform,
this.transform,
scratchTransform,
);
const transformChanged = !Matrix4.equals(
computedTransform,
this.computedTransform,
);
const exaggerationChanged =
defined(frameState) &&
(this._verticalExaggeration !== frameState.verticalExaggeration ||
this._verticalExaggerationRelativeHeight !==
frameState.verticalExaggerationRelativeHeight);
if (!transformChanged && !exaggerationChanged) {
return;
}
if (transformChanged) {
Matrix4.clone(computedTransform, this.computedTransform);
}
if (exaggerationChanged) {
this._verticalExaggeration = frameState.verticalExaggeration;
this._verticalExaggerationRelativeHeight =
frameState.verticalExaggerationRelativeHeight;
}
// Update the bounding volumes
const header = this._header;
const contentHeader = this._contentHeader;
this._boundingVolume = this.createBoundingVolume(
header.boundingVolume,
this.computedTransform,
this._boundingVolume,
);
if (defined(this._contentBoundingVolume)) {
this._contentBoundingVolume = this.createBoundingVolume(
contentHeader.boundingVolume,
this.computedTransform,
this._contentBoundingVolume,
);
}
Iif (defined(this._viewerRequestVolume)) {
this._viewerRequestVolume = this.createBoundingVolume(
header.viewerRequestVolume,
this.computedTransform,
this._viewerRequestVolume,
);
}
this.updateGeometricErrorScale();
// Destroy the debug bounding volumes. They will be generated fresh.
this._debugBoundingVolume =
this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume =
this._debugContentBoundingVolume &&
this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume =
this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
};
Cesium3DTile.prototype.updateGeometricErrorScale = function () {
const scale = Matrix4.getScale(this.computedTransform, scratchScale);
const uniformScale = Cartesian3.maximumComponent(scale);
this.geometricError = this._geometricError * uniformScale;
if (!defined(this.parent)) {
// Update the tileset's geometric error
const tileset = this._tileset;
tileset._scaledGeometricError = tileset._geometricError * uniformScale;
}
};
/**
* @private
* @param {Cesium3DTile} tile
* @param {Cesium3DTileset} tileset
* @param {FrameState} frameState
* @param {object} passOptions
*/
function applyDebugSettings(tile, tileset, frameState, passOptions) {
if (!passOptions.isRender) {
return;
}
const hasContentBoundingVolume =
defined(tile._contentHeader) && defined(tile._contentHeader.boundingVolume);
const showVolume =
tileset.debugShowBoundingVolume ||
(tileset.debugShowContentBoundingVolume && !hasContentBoundingVolume);
if (showVolume) {
let color;
Iif (!tile._finalResolution) {
color = Color.YELLOW;
} else if (!tile.hasRenderableContent) {
color = Color.DARKGRAY;
} else {
color = Color.WHITE;
}
Eif (!defined(tile._debugBoundingVolume)) {
tile._debugBoundingVolume = tile._boundingVolume.createDebugVolume(color);
}
tile._debugBoundingVolume.update(frameState);
const attributes =
tile._debugBoundingVolume.getGeometryInstanceAttributes("outline");
attributes.color = ColorGeometryInstanceAttribute.toValue(
color,
attributes.color,
);
} else if (!showVolume && defined(tile._debugBoundingVolume)) {
tile._debugBoundingVolume = tile._debugBoundingVolume.destroy();
}
if (tileset.debugShowContentBoundingVolume && hasContentBoundingVolume) {
Eif (!defined(tile._debugContentBoundingVolume)) {
tile._debugContentBoundingVolume =
tile._contentBoundingVolume.createDebugVolume(Color.BLUE);
}
tile._debugContentBoundingVolume.update(frameState);
} else if (
!tileset.debugShowContentBoundingVolume &&
defined(tile._debugContentBoundingVolume)
) {
tile._debugContentBoundingVolume =
tile._debugContentBoundingVolume.destroy();
}
if (
tileset.debugShowViewerRequestVolume &&
defined(tile._viewerRequestVolume)
) {
Eif (!defined(tile._debugViewerRequestVolume)) {
tile._debugViewerRequestVolume =
tile._viewerRequestVolume.createDebugVolume(Color.YELLOW);
}
tile._debugViewerRequestVolume.update(frameState);
} else if (
!tileset.debugShowViewerRequestVolume &&
defined(tile._debugViewerRequestVolume)
) {
tile._debugViewerRequestVolume = tile._debugViewerRequestVolume.destroy();
}
const debugColorizeTilesOn =
(tileset.debugColorizeTiles && !tile._debugColorizeTiles) ||
defined(tileset._heatmap.tilePropertyName);
const debugColorizeTilesOff =
!tileset.debugColorizeTiles && tile._debugColorizeTiles;
if (debugColorizeTilesOn) {
tileset._heatmap.colorize(tile, frameState); // Skipped if tileset._heatmap.tilePropertyName is undefined
tile._debugColorizeTiles = true;
tile.color = tile._debugColor;
} else if (debugColorizeTilesOff) {
tile._debugColorizeTiles = false;
tile.color = Color.WHITE;
}
if (tile._colorDirty) {
tile._colorDirty = false;
tile._content.applyDebugSettings(true, tile._color);
}
if (debugColorizeTilesOff) {
tileset.makeStyleDirty(); // Re-apply style now that colorize is switched off
}
}
/**
* @private
* @param {Cesium3DTile} tile
* @param {Cesium3DTileset} tileset
* @param {FrameState} frameState
*/
function updateContent(tile, tileset, frameState) {
const expiredContent = tile._expiredContent;
// expired content is not supported for multiple contents
if (!tile.hasMultipleContents && defined(expiredContent)) {
if (!tile.contentReady) {
// Render the expired content while the content loads
try {
expiredContent.update(tileset, frameState);
} catch (error) {
// Eat error for expired content
}
return;
}
// New content is ready, destroy expired content
tile._expiredContent.destroy();
tile._expiredContent = undefined;
}
if (!defined(tile.content)) {
// Implicit placeholder tile
return;
}
try {
tile.content.update(tileset, frameState);
} catch (error) {
tile._contentState = Cesium3DTileContentState.FAILED;
throw error;
}
}
/**
* Compute and compare ClippingPlanes state:
* - enabled-ness - are clipping planes enabled? is this tile clipped?
* - clipping plane count
* - clipping function (union v. intersection)
* @private
* @param {Cesium3DTile} tile
* @param {Cesium3DTileset} tileset
*/
function updateClippingPlanes(tile, tileset) {
const clippingPlanes = tileset.clippingPlanes;
let currentClippingPlanesState = 0;
if (defined(clippingPlanes) && tile._isClipped && clippingPlanes.enabled) {
currentClippingPlanesState = clippingPlanes.clippingPlanesState;
}
// If clippingPlaneState for tile changed, mark clippingPlanesDirty so content can update
if (currentClippingPlanesState !== tile._clippingPlanesState) {
tile._clippingPlanesState = currentClippingPlanesState;
tile.clippingPlanesDirty = true;
}
}
/**
* Compute and compare ClippingPolygons state:
* - enabled-ness - are clipping polygons enabled? is this tile clipped?
* - clipping polygon count & position count
* - clipping function (inverse)
* @private
* @param {Cesium3DTile} tile
* @param {Cesium3DTileset} tileset
*/
function updateClippingPolygons(tile, tileset) {
const clippingPolygons = tileset.clippingPolygons;
let currentClippingPolygonsState = 0;
Iif (
defined(clippingPolygons) &&
tile._isClippedByPolygon &&
clippingPolygons.enabled
) {
currentClippingPolygonsState = clippingPolygons.clippingPolygonsState;
}
// If clippingPolygonState for tile changed, mark clippingPolygonsDirty so content can update
Iif (currentClippingPolygonsState !== tile._clippingPolygonsState) {
tile._clippingPolygonsState = currentClippingPolygonsState;
tile.clippingPolygonsDirty = true;
}
}
/**
* Get the draw commands needed to render this tile.
*
* @private
* @param {Cesium3DTileset} tileset
* @param {FrameState} frameState
* @param {object} passOptions
*/
Cesium3DTile.prototype.update = function (tileset, frameState, passOptions) {
const { commandList } = frameState;
const commandStart = commandList.length;
updateClippingPlanes(this, tileset);
updateClippingPolygons(this, tileset);
applyDebugSettings(this, tileset, frameState, passOptions);
updateContent(this, tileset, frameState);
const commandEnd = commandList.length;
this._commandsLength = commandEnd - commandStart;
for (let i = commandStart; i < commandEnd; ++i) {
const command = commandList[i];
const translucent = command.pass === Pass.TRANSLUCENT;
command.depthForTranslucentClassification = translucent;
}
this.clippingPlanesDirty = false; // reset after content update
this.clippingPolygonsDirty = false;
};
const scratchCommandList = [];
/**
* Processes the tile's content, e.g., create WebGL resources, to move from the PROCESSING to READY state.
*
* @param {Cesium3DTileset} tileset The tileset containing this tile.
* @param {FrameState} frameState The frame state.
*
* @private
*/
Cesium3DTile.prototype.process = function (tileset, frameState) {
if (!this.contentExpired && !this.contentReady && this._content.ready) {
updateExpireDate(this);
// Refresh style for expired content
this._selectedFrame = 0;
this.lastStyleTime = 0.0;
JulianDate.now(this._loadTimestamp);
this._contentState = Cesium3DTileContentState.READY;
if (!this.hasTilesetContent && !this.hasImplicitContent) {
// RESEARCH_IDEA: ability to unload tiles (without content) for an
// external tileset when all the tiles are unloaded.
tileset._statistics.incrementLoadCounts(this.content);
++tileset._statistics.numberOfTilesWithContentReady;
++tileset._statistics.numberOfLoadedTilesTotal;
// Add to the tile cache. Previously expired tiles are already in the cache and won't get re-added.
tileset._cache.add(this);
}
}
const savedCommandList = frameState.commandList;
frameState.commandList = scratchCommandList;
try {
this._content.update(tileset, frameState);
} catch (error) {
this._contentState = Cesium3DTileContentState.FAILED;
throw error;
}
scratchCommandList.length = 0;
frameState.commandList = savedCommandList;
};
/**
* @private
* @param {number} normalizedValue
* @param {number} numberOfDigits
* @param {number} leftShift
* @returns {number}
*/
function isolateDigits(normalizedValue, numberOfDigits, leftShift) {
const scaled = normalizedValue * Math.pow(10, numberOfDigits);
const integer = parseInt(scaled);
return integer * Math.pow(10, leftShift);
}
/**
* @private
* @param {number} value
* @param {number} minimum
* @param {number} maximum
* @returns {number}
*/
function priorityNormalizeAndClamp(value, minimum, maximum) {
// Subtract epsilon since we only want decimal digits present in the output.
return Math.max(
CesiumMath.normalize(value, minimum, maximum) - CesiumMath.EPSILON7,
0.0,
);
}
/**
* Sets the priority of the tile based on distance and depth
* @private
*/
Cesium3DTile.prototype.updatePriority = function () {
const tileset = this.tileset;
const preferLeaves = tileset.preferLeaves;
const minimumPriority = tileset._minimumPriority;
const maximumPriority = tileset._maximumPriority;
// Combine priority systems together by mapping them into a base 10 number where each priority controls a specific set of digits in the number.
// For number priorities, map them to a 0.xxxxx number then left shift it up into a set number of digits before the decimal point. Chop of the fractional part then left shift again into the position it needs to go.
// For blending number priorities, normalize them to 0-1 and interpolate to get a combined 0-1 number, then proceed as normal.
// Booleans can just be 0 or 10^leftshift.
// Think of digits as penalties since smaller numbers are higher priority. If a tile has some large quantity or has a flag raised it's (usually) penalized for it, expressed as a higher number for the digit.
// Priority number format: preloadFlightDigits(1) | foveatedDeferDigits(1) | foveatedDigits(4) | preloadProgressiveResolutionDigits(1) | preferredSortingDigits(4) . depthDigits(the decimal digits)
// Certain flags like preferLeaves will flip / turn off certain digits to get desired load order.
// Setup leftShifts, digit counts, and scales (for booleans)
const digitsForANumber = 4;
const digitsForABoolean = 1;
const preferredSortingLeftShift = 0;
const preferredSortingDigitsCount = digitsForANumber;
const foveatedLeftShift =
preferredSortingLeftShift + preferredSortingDigitsCount;
const foveatedDigitsCount = digitsForANumber;
const preloadProgressiveResolutionLeftShift =
foveatedLeftShift + foveatedDigitsCount;
const preloadProgressiveResolutionDigitsCount = digitsForABoolean;
const preloadProgressiveResolutionScale = Math.pow(
10,
preloadProgressiveResolutionLeftShift,
);
const foveatedDeferLeftShift =
preloadProgressiveResolutionLeftShift +
preloadProgressiveResolutionDigitsCount;
const foveatedDeferDigitsCount = digitsForABoolean;
const foveatedDeferScale = Math.pow(10, foveatedDeferLeftShift);
const preloadFlightLeftShift =
foveatedDeferLeftShift + foveatedDeferDigitsCount;
const preloadFlightScale = Math.pow(10, preloadFlightLeftShift);
// Compute the digits for each priority
let depthDigits = priorityNormalizeAndClamp(
this._depth,
minimumPriority.depth,
maximumPriority.depth,
);
depthDigits = preferLeaves ? 1.0 - depthDigits : depthDigits;
// Map 0-1 then convert to digit. Include a distance sort when doing non-skipLOD and replacement refinement, helps things like non-skipLOD photogrammetry
const useDistance =
!tileset.isSkippingLevelOfDetail &&
this.refine === Cesium3DTileRefine.REPLACE;
const normalizedPreferredSorting = useDistance
? priorityNormalizeAndClamp(
this._priorityHolder._distanceToCamera,
minimumPriority.distance,
maximumPriority.distance,
)
: priorityNormalizeAndClamp(
this._priorityReverseScreenSpaceError,
minimumPriority.reverseScreenSpaceError,
maximumPriority.reverseScreenSpaceError,
);
const preferredSortingDigits = isolateDigits(
normalizedPreferredSorting,
preferredSortingDigitsCount,
preferredSortingLeftShift,
);
const preloadProgressiveResolutionDigits = this._priorityProgressiveResolution
? 0
: preloadProgressiveResolutionScale;
const normalizedFoveatedFactor = priorityNormalizeAndClamp(
this._priorityHolder._foveatedFactor,
minimumPriority.foveatedFactor,
maximumPriority.foveatedFactor,
);
const foveatedDigits = isolateDigits(
normalizedFoveatedFactor,
foveatedDigitsCount,
foveatedLeftShift,
);
const foveatedDeferDigits = this.priorityDeferred ? foveatedDeferScale : 0;
const preloadFlightDigits =
tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ? 0 : preloadFlightScale;
// Get the final base 10 number
this._priority =
depthDigits +
preferredSortingDigits +
preloadProgressiveResolutionDigits +
foveatedDigits +
foveatedDeferDigits +
preloadFlightDigits;
};
/**
* @private
*/
Cesium3DTile.prototype.isDestroyed = function () {
return false;
};
/**
* @private
*/
Cesium3DTile.prototype.destroy = function () {
// For the interval between new content being requested and downloaded, expiredContent === content, so don't destroy twice
this._content = this._content && this._content.destroy();
this._expiredContent =
this._expiredContent &&
!this._expiredContent.isDestroyed() &&
this._expiredContent.destroy();
this._debugBoundingVolume =
this._debugBoundingVolume && this._debugBoundingVolume.destroy();
this._debugContentBoundingVolume =
this._debugContentBoundingVolume &&
this._debugContentBoundingVolume.destroy();
this._debugViewerRequestVolume =
this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
return destroyObject(this);
};
export default Cesium3DTile;
|