/usr/src/castle-game-engine-5.0.0/x3d/x3dfields.pas is in castle-game-engine-src 5.0.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 | {
Copyright 2002-2014 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" 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.
----------------------------------------------------------------------------
}
{ VRML fields (TX3DField and many descendants). }
unit X3DFields;
interface
uses CastleVectors, Classes, SysUtils, X3DLexer, CastleUtils, CastleClassUtils,
CastleImages, CastleStringUtils, CastleInterfaces, X3DTime, DOM,
FGL, CastleGenericLists, CastleColors;
{$define read_interface}
const
DefaultRotation: TVector4Single = (0, 0, 1, 0);
type
EX3DFieldAssign = class(Exception);
EX3DFieldAssignInvalidClass = class(EX3DFieldAssign);
{ Raised by various X3D methods searching for X3D items (nodes, fields,
events and such) when given item cannot be found. }
EX3DNotFound = class(Exception);
TX3DEvent = class;
{ Writer of VRML/X3D to stream. }
TX3DWriter = {abstact} class
private
Indent: string;
DoDiscardNextIndent: boolean;
FEncoding: TX3DEncoding;
FStream: TStream;
public
{ Which VRML/X3D version are we writing. Read-only after creation. }
Version: TX3DVersion;
constructor Create(AStream: TStream;
const AVersion: TX3DVersion; const AEncoding: TX3DEncoding);
destructor Destroy; override;
property Encoding: TX3DEncoding read FEncoding;
procedure IncIndent;
procedure DecIndent;
{ Comfortable routines that simply write given string to a stream.
@groupBegin }
procedure Write(const S: string);
procedure Writeln(const S: string); overload;
procedure Writeln; overload;
procedure WriteIndent(const S: string);
procedure WritelnIndent(const S: string);
{ @groupEnd }
{ Causes next WriteIndent or WritelnIndent too not write the Indent.
Useful in some cases to improve readability of generated VRML file. }
procedure DiscardNextIndent;
end;
{ Reading of VRML/X3D from stream.
Common knowledge for both classic and XML reader.
X3DNodes unit extends this into TX3DReaderNames. }
TX3DReader = class
private
FVersion: TX3DVersion;
FBaseUrl: string;
AngleConversionFactor: Float;
public
LengthConversionFactor: Float;
constructor Create(const ABaseUrl: string;
const AVersion: TX3DVersion);
constructor CreateCopy(Source: TX3DReader);
{ Base path for resolving URLs from nodes in this namespace.
See TX3DNode.BaseUrl. }
property BaseUrl: string read FBaseUrl;
{ VRML/X3D version number. For resolving node class names and other stuff. }
property Version: TX3DVersion read FVersion;
{ Apply unit convertion.
If this is angle convertion factor, it is stored and used internally.
If this is length convertion factor, we update our
LengthConversionFactor property, but it's callers responsibility
to make use of it. (You want to use here TX3DRootNode.Scale.) }
procedure UnitConversion(const Category, Name: string;
const ConversionFactor: Float);
end;
TSaveToXmlMethod = (sxNone, sxAttribute, sxAttributeCustomQuotes, sxChildElement);
{ Possible things that happen when given field is changed.
Used by TX3DField.ExecuteChanges. }
TX3DChange = (
{ Something visible in the geometry changed.
See vcVisibleGeometry.
This means that VisibleChangeHere with vcVisibleGeometry included should
be called. }
chVisibleGeometry,
{ Something visible changed, but not geometry.
See vcVisibleNonGeometry.
This means that VisibleChangeHere with vcVisibleNonGeometry included should
be called. }
chVisibleNonGeometry,
{ Camera changed.
See vcCamera.
This means that VisibleChangeHere with vcCamera included should
be called. }
chCamera,
{ Call VisibleChangeHere to redisplay the scene.
If you include one of the chVisibleGeometry, chVisibleNonGeometry,
chCamera then this flag (chRedisplay) makes no effect.
Otherwise, this flag should be used if your change requires
redisplay of the 3D view for some other reasons. }
chRedisplay,
{ Transformation of children of this node changed.
Caller will analyze the scene (your children) to know what this implicates,
don't include other flags with this. }
chTransform,
{ Coordinate (both VRML 1.0 and >= 2.0) node "point" field changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chCoordinate,
{ Something visible in VRML 1.0 state node (that may be present
in TX3DGraphTraverseState.LastNodes) changed, but not geometry.
Excluding Coordinate node change (this one should go through chCoordinate
only).
This is allowed, and ignored, on nodes that are not part of VRML 1.0
state. (This is useful for alphaChannel field, that is declared
in TAbstractGeometryNode, and so is part of some VRML 1.0 state nodes
but is also part of VRML >= 2.0 nodes.)
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: you can (and should) include chUseBlending and
chTextureImage for appropriate changes. }
chVisibleVRML1State,
{ Some visible geometry changed because of VRML 1.0 state node change.
This is for VRML 1.0 state node changes, excluding non-geometry changes
(these go to chVisibleVRML1State) and Coordinate changes (these go to
chCoordinate).
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chGeometryVRML1State,
{ Something visible in VRML >= 2.0 Material (or TwoSidedMaterial) changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: you can (and should) include chUseBlending for appropriate
Material changes. }
chMaterial2,
{ Something that may affect UseBlending calculation possibly changed.
This is guaranteed to work only when used together with
chVisibleVRML1State and chMaterial2. It's understood that only
shapes that use given material need UseBlending recalculated. }
chUseBlending,
{ Light property that is also reflected in TLightInstance structure.
Only allowed on node's descending from TAbstractLightNode.
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: include also chLightLocationDirection when appropriate. }
chLightInstanceProperty,
{ Light's location and/or direction changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: include also chLightInstanceProperty when appropriate. }
chLightLocationDirection,
{ TCastleSceneCore.MainLightForShadows possibly changed because of this change.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chLightForShadowVolumes,
{ Switch.whichChoice changed, for VRML >= 2.0.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chSwitch2,
{ X3DColorNode colors changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chColorNode,
{ X3DTextureCoordinateNode coords changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chTextureCoordinate,
{ VRML >= 2.0 TextureTransform changed.
Not for multi-texture node changes, only the simple nodes changes.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chTextureTransform,
{ Geometry node visible (or collidable) changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chGeometry,
{ X3DEnvironmentalSensorNode bounds (size/center) changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chEnvironmentalSensorBounds,
{ TimeDependent node is start/stop/pause/resume time changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chTimeStopStart,
{ Viewpoint vectors (position, direction, up, gravity up) changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chViewpointVectors,
{ Viewpoint projection changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chViewpointProjection,
{ Texture image (data) needs reloading (url or source SFImage
data changed). This is for TAbstractTexture2DNode, or TAbstractTexture3DNode.
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: you can mix it with chVisibleVRML1State or
chTextureRendererProperties. }
chTextureImage,
{ Texture properties used by the renderer changed (something other than
only the texture data). This is for fields contained in X3DTextureNode.
Caller will analyze the scene to know what this implicates,
don't include other flags with this.
Exception: you can mix it with chTextureImage. }
chTextureRendererProperties,
{ Texture properties inside TextureProperties node changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chTexturePropertiesNode,
{ What is considered a shadow caster changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chShadowCasters,
{ Mark the generated texture node (parent of this field) as requiring update
(assuming it's "update" field value wants it too).
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chGeneratedTextureUpdateNeeded,
{ VRML >= 2.0 FontStyle changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chFontStyle,
{ HeadLight on status changed.
Caller will analyze the scene to know what this implicates,
don't include other flags with this. }
chHeadLightOn,
{ Clip plane visible change (enabled or plane equation). }
chClipPlane,
{ Enabled field of the pointing-device drag sensor changed.
Use only for TSFBool fields within TAbstractDragSensorNode. }
chDragSensorEnabled,
{ NavigationInfo field value used in TCastleSceneCore.CameraFromNavigationInfo
changed. }
chNavigationInfo,
{ ScreenEffect.enabled changed }
chScreenEffectEnabled,
{ X3DBackgroundNode properties that are stored inside TBackground
display list have changed. }
chBackground,
{ Everything changed and needs to be recalculated.
This is needed for changes on stuff internally cached in
TCastleSceneCore, TCastleScene, TShape that cannot be expressed
as one of above flags.
Use only as a last resort, as this is very costly!
(And in an ideal implementation, should not be needed.)
Don't include other flags with this. }
chEverything,
{ Higher-level shadow maps fields changed.
They have to be processed to lower-level fields by calling
TCastleSceneCore.ProcessShadowMapsReceivers.
Don't include other flags with this. }
chShadowMaps);
TX3DChanges = set of TX3DChange;
{ ---------------------------------------------------------------------------- }
{ @section(Base fields classes) }
{ Base class for any item within VRML/X3D file: a node, a field, a route,
a prototype etc. We need a common base class for all such things
to store PositionInParent.
About ancestry: TX3DFieldOrEvent make use of Assign mechanism
and so need to descend from TPersistent. TX3DNode make use
of interfaces and so must descend from something like
TNonRefCountedInterfacedXxx. These are the only reasons, for now,
why this descends from TNonRefCountedInterfacedPersistent. }
TX3DFileItem = class(TNonRefCountedInterfacedPersistent)
private
FPositionInParent: Integer;
{ Secondary order for saving items to VRML/X3D file.
When PositionInParent are equal, this decides which item is first.
It may be useful, since SortPositionInParent is not a stable sort
(because QuickSort is not stable), so using this to preserve order
may be helpful.
TX3DFileItemList.Add sets this, which allows to preserve
order when saving. }
PositionOnList: Integer;
public
constructor Create;
{ Position of this item within parent VRML/X3D node, used for saving
the VRML/X3D graph to file. Default value -1 means "undefined".
For normal usage and processing of VRML graph, this is totally not needed.
This position doesn't dictate actual meaning of VRML graph.
If you're looking to change order of nodes, you probably want
to rather look at something like ReplaceItems within TMFNode or such.
This field is purely a hint when encoding VRML file how to order
VRML items (nodes, fields, routes, protos) within parent node
or the VRML file. Reason: VRML allows non-unique node names.
Each DEF XXX overrides all previous ("previous" in lexical sense,
i.e. normal order of tokens in the file) DEF XXX with the same XXX,
thus hiding previous node name "XXX".
This means that when saving VRML file we have to be very careful
about the order of items, such that e.g. all routes are specified
when appropriate node names are bound.
This is a relative position, relative to other PositionInParent
value of other TX3DFileItem items. So it's not necessary
to keep all PositionInParent different or successive within some
parent. When saving, we will sort everything according to
PositionInParent.
See e.g. ../../../demo_models/x3d/tricky_def_use.x3dv
for tests of some tricky layout. When reading such file we have
to record PositionInParent to be able to save such file correctly. }
property PositionInParent: Integer
read FPositionInParent write FPositionInParent default -1;
{ Save to stream. }
procedure SaveToStream(Writer: TX3DWriter); virtual; abstract;
{ How is this saved to X3D XML encoding. This determines when
SaveToStream is called. It also cooperates with some SaveToStream
implementations, guiding how the item is actually saved.
By default it is sxChildElement. }
function SaveToXml: TSaveToXmlMethod; virtual;
end;
TX3DFileItemList = class(specialize TFPGObjectList<TX3DFileItem>)
public
procedure SortPositionInParent;
{ Sort all items by PositionInParent and then save them all to stream. }
procedure SaveToStream(Writer: TX3DWriter);
procedure Add(Item: TX3DFileItem);
end;
{ Base class for VRML/X3D field or event. }
TX3DFieldOrEvent = class(TX3DFileItem)
private
{ To optimize memory usage (which may really be huge in case of VRML/X3D
with many nodes, esp. when VRML/X3D uses a lot of prototypes),
this is only created when needed (when it is not empty).
Otherwise it is @nil. }
FIsClauseNames: TCastleStringList;
FName: string;
{ A really simple (but good enough for now) implementation of
AddAlternativeName:
- there are only 0 (none), 1, 2, and 3 VRML major versions
- each VRML major version has exactly one alt name
- alt name is never '' ('' means that alt name doesn't exist) }
FAlternativeNames: array [0..3] of string;
FParentNode: TX3DFileItem;
FParentInterfaceDeclaration: TX3DFileItem;
function GetIsClauseNames(const Index: Integer): string;
{ Return FIsClauseNames, initializing it if necessary to not be nil. }
function IsClauseNamesCreate: TCastleStringList;
protected
procedure FieldOrEventAssignCommon(Source: TX3DFieldOrEvent);
public
constructor Create(AParentNode: TX3DFileItem; const AName: string);
destructor Destroy; override;
{ Name of the field or event.
Normal fields/events are inside some VRML node, and then
they should have a name <> ''. But in some special cases I use
fields without a name, then this is ''.
Note that you cannot change this after object creation, since
Name is used for various purposes (like to generate names for
TX3DField.ExposedEvents). }
property Name: string read FName;
{ VRML node containing this field/event.
This must always contain an instance
of TX3DNode class (although it cannot be declared such, since X3DFields
unit cannot depend on X3DNodes interface).
It may be @nil for special fields/events when parent node is unknown. }
property ParentNode: TX3DFileItem read FParentNode;
{ "IS" clauses of this field/event, used when this field/event
is inside prototype definition.
This is an array, as one item may have many "IS" clauses (for a field,
only one "IS" clause should refer to another field;
but you can have many "IS" clauses connecting events,
also exposedField may have "IS" clause that should be interpreted
actually as links to it's exposed events).
See e.g. @code(demo_models/x3d/proto_events_test_3.x3dv).
Note that having "IS" clauses doesn't mean that the field should
be considered "without any value". This is not a good way of thinking,
as an exposed field may have an "IS" clause, but linking it to an event,
and thus such field has it's value (default value, if not specified
in the file), event though it also has an "IS" clause.
Although there is TX3DField.ValueFromIsClause, which indicates
whether current value was obtained from "IS" clause.
To be able to significantly optimize memory, we do not expose IsClauseNames
as TCastleStringList. Instead operate on them only using below functions.
Note that IsClauseNamesAssign can also accept @nil as parameter.
@groupBegin }
property IsClauseNames[const Index: Integer]: string read GetIsClauseNames;
function IsClauseNamesCount: Integer;
procedure IsClauseNamesAssign(const SourceIsClauseNames: TCastleStringList);
procedure IsClauseNamesAdd(const S: string);
{ @groupEnd }
{ Parse only "IS" clause, if it's not present --- don't do nothing.
For example, for the TX3DField descendant, this does not try to parse
field value. }
procedure ParseIsClause(Lexer: TX3DLexer);
{ Add alternative name for the same field/event, to be used in different
VRML version.
When VRML major version is exactly equal VrmlMajorVersion,
the AlternativeName should be used --- for both reading and writing
of this field/event. In some cases, when reading, we may also allow
all versions (both original and alternative), but this is mostly
for implementation simplicity --- don't count on it.
A special value 0 for VrmlMajorVersion means that this is just
an alternative name, that should be allowed when reading (as alternative
to normal Name), and never used when writing.
Alternative names is a very handy mechanism for cases when
the only thing that changed between VRML versions is the field
name. Example: Switch node's children/choice, LOD node's children/level,
Polyline2D lineSegments/point.
Note that this also works for ExposedEvents with exposed TX3DField:
if a field has alternative names, then it's exposed events always also
have appropriate alternative names. }
procedure AddAlternativeName(const AlternativeName: string;
VrmlMajorVersion: Integer); virtual;
{ Returns if S matches current Name or one of the alternative names.
Think about it like simple test "Name = S", but actually this
checks also names added by AddAlternativeName method. }
function IsName(const S: string): boolean;
{ Return how this field should be named for given VRML version.
In almost all cases, this simply returns current Name.
But it can also return a name added by AddAlternativeName method. }
function NameForVersion(Version: TX3DVersion): string; overload;
function NameForVersion(Writer: TX3DWriter): string; overload;
{ For fields contained in TX3DInterfaceDeclaration.
This should always be @nil (if the field is normal, standard field,
not coming from interface declaration in VRML file) or an instance of
TX3DInterfaceDeclaration. (But it cannot be declared such,
since TX3DInterfaceDeclaration is not known in this unit). }
property ParentInterfaceDeclaration: TX3DFileItem
read FParentInterfaceDeclaration write FParentInterfaceDeclaration;
{ Nice and concise field description for user.
Describes parent node type, name and field/event's name. }
function NiceName: string;
{ Save IS clauses to stream, only for classic encoding.
For each IS clause, writeln field/event name followed by "IS" clause. }
procedure SaveToStreamClassicIsClauses(Writer: TX3DWriter);
end;
TX3DFieldOrEventList = specialize TFPGObjectList<TX3DFieldOrEvent>;
TX3DEventReceiveList = class;
TX3DFieldClass = class of TX3DField;
{ Base class for all VRML/X3D fields.
Common notes for all descendants: most of them expose field or property
"Value", this is (surprise, surprise!) the value of the field.
Many of them also expose DefaultValue and DefaultValueExists
fields/properties, these should be the default VRML value for this field.
You can even change DefaultValue after the object is created.
Most of descendants include constructor that initializes
both DefaultValue and Value to the same thing, as this is what
you usually want.
Some notes about @code(Assign) method (inherited from TPersistent and
overridied appropriately in TX3DField descendants):
@orderedList(
@item(There are some exceptions, but usually
assignment is possible only when source and destination field classes
are equal.)
@item(Assignment (by @code(Assign), inherited from TPersistent)
tries to copy everything: name (with alternative names), default value,
IsClauseNames, ValueFromIsClause, Exposed, and of course current value.
Exceptions are things related to hierarchy of containers:
ParentNode, ParentInterfaceDeclaration. Also ExposedEventsLinked.
If you want to copy only the current value, use AssignValue
(or AssignLerp, where available).))
}
TX3DField = class(TX3DFieldOrEvent)
private
FExposed: boolean;
FExposedEvents: array [boolean] of TX3DEvent;
FChangesAlways: TX3DChanges;
FValueFromIsClause: boolean;
FExposedEventsLinked: boolean;
procedure SetExposed(Value: boolean);
function GetExposedEvents(InEvent: boolean): TX3DEvent;
procedure SetExposedEventsLinked(const Value: boolean);
protected
{ Save field value to a stream. Must be overriden for each specific
field.
For classic encoding, FieldSaveToStream and SaveToStream write
Indent, Name, ' ', then call SaveToStreamValue, then write @link(NL).
IS clauses are not saved by FieldSaveToStream or SaveToStream.
(They must be saved specially, by SaveToStreamClassicIsClauses
or special XML output.)
SaveToStream still checks ValueFromIsClause, if ValueFromIsClause
we will not call SaveToStreamValue. So when overriding
SaveToStreamValue, you can safely assume that ValueFromIsClause
is @false. }
procedure SaveToStreamValue(Writer: TX3DWriter); virtual; abstract;
{ Save method of SaveToStreamValue. May assume things that
SaveToStreamValue may issume, for example: if this is used at all,
then at least field value is not default (so there is a need to write
this field) and such. }
function SaveToXmlValue: TSaveToXmlMethod; virtual;
{ Call this inside overriden Assign methods.
I don't want to place this inside TX3DField.Assign, since I want
"inherited" in Assign methods to cause exception. }
procedure VRMLFieldAssignCommon(Source: TX3DField);
procedure AssignValueRaiseInvalidClass(Source: TX3DField);
{ Class of the fields allowed in the exposed events of this field.
This should usually be using ClassType of this object,
and this is the default implementation of this method in TX3DField.
You can override this to return some ancestor (from which, and to which,
you can assign) if your TX3DField descendant
doesn't change how the @code(Assign) method works.
E.g. TSFTextureUpdate class, that wants to be fully compatible with normal
TSFString. }
class function ExposedEventsFieldClass: TX3DFieldClass; virtual;
{ Handle exposed input event. In TX3DField class, this does everything
usually needed --- assigns value, sends an output event, notifies
@link(Changed).
You can override this for some special purposes. For special needs,
you do not even need to call @code(inherited) in overriden versions.
This is suitable e.g. for cases when TimeSensor.set_startTime or such
must be ignored. }
procedure ExposedEventReceive(Event: TX3DEvent; Value: TX3DField;
const Time: TX3DTime); virtual;
public
{ Normal constructor.
@italic(Descendants implementors notes:)
when implementing constructors in descendants,
remember that Create in this class actually just calls CreateUndefined,
and CreateUndefined is virtual. So when calling @code(inherited Create),
be aware that actually you may be calling your own overriden
CreateUndefined.
In fact, in descendants you should focus on moving all the work to
CreateUndefined constructor.
The Create constructor should be just a comfortable extension of
CreateUndefined, that does the same and addiionally gets parameters
that specify default field value. }
constructor Create(AParentNode: TX3DFileItem;
const AName: string);
{ Virtual constructor, that you can use to construct field instance when
field class is known only at runtime.
The idea is that in some cases, you need to create fields using
variable like FieldClass: TX3DFieldClass. See e.g. TX3DInterfaceDeclaration,
VRML 2.0 feature that simply requires this ability, also
implementation of TX3DSimpleMultField.Parse and
TX3DSimpleMultField.CreateItemBeforeParse.
Later you can initialize such instance from string using it's Parse method.
Note that some exceptional fields simply cannot work when initialized
by this constructor: these are SFEnum and SFBitMask fields.
They simply need to know their TSFEnum.EnumNames, or
TSFBitMask.FlagNames + TSFBitMask.NoneString + TSFBitMask.AllString
before they can be parsed. I guess that's one of the reasons why these
field types were entirely removed from VRML 2.0. }
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); virtual;
destructor Destroy; override;
{ Parse inits properties from Lexer.
In this class, Parse only appends to IsClauseNames:
if we stand on "IS" clause (see VRML 2.0 spec about "IS" clause)
and IsClauseAllowed then we append specified identifier to
IsClauseNames.
If "IS" clause not found, we call ParseValue which should
actually parse field's value.
Descendants should override ParseValue. }
procedure Parse(Lexer: TX3DLexer; Reader: TX3DReader; IsClauseAllowed: boolean);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); virtual; abstract;
{ Parse field value from X3D XML encoded attribute using a Lexer.
Attributes in X3D are generally encoded such that normal
@code(ParseValue(Lexer, nil)) call is appropriate,
so this is done in this class. }
procedure ParseXMLAttributeLexer(Lexer: TX3DLexer; Reader: TX3DReader); virtual;
{ Parse field value from X3D XML encoded attribute.
Implementation in this class creates a Lexer to parse the string,
and calls ParseXMLAttributeLexer. }
procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); virtual;
{ Parse field's value from XML Element children.
This is used to read SFNode / MFNode field value inside <field>
(for interface declaration default field value) and <fieldValue>
inside <ProtoInstance>. }
procedure ParseXMLElement(Element: TDOMElement; Reader: TX3DReader); virtual;
{ Save the field to the stream.
Field name (if set, omitted if empty) and value are saved.
Unless the current field value equals default value and
FieldSaveWhenDefault is @false (default), then nothing is saved.
IS clauses are not saved here (because they often have to be treated
specially anyway, for XML encoding, for prototype declarations etc.). }
procedure FieldSaveToStream(Writer: TX3DWriter;
FieldSaveWhenDefault: boolean = false;
XmlAvoidSavingNameBeforeValue: boolean = false);
{ Save the field to the stream.
This simply calls FieldSaveToStream(Writer).
See FieldSaveToStream for more comments and when you need control over
FieldSaveWhenDefault behavior.
It doesn't actually save anything if field value is defined
and equals default value. }
procedure SaveToStream(Writer: TX3DWriter); override;
function SaveToXml: TSaveToXmlMethod; override;
{ Does current field value came from expanding "IS" clause.
If yes, then saving this field to stream will only save it's "IS" clauses,
never saving actual value. }
property ValueFromIsClause: boolean
read FValueFromIsClause write FValueFromIsClause;
{ Zwraca zawsze false w tej klasie. Mozesz to przedefiniowac w podklasach
aby SaveToStream nie zapisywalo do strumienia pol o wartosci domyslnej. }
function EqualsDefaultValue: boolean; virtual;
{ @true if the SecondValue object has exactly the same type and properties.
For this class, this returns just (SecondValue.Name = Name).
All descendants (that add some property that should be compared)
should override this like
@longCode(#
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TMyType) and
(TMyType(SecondValue).MyProperty = MyProperty);
#)
For varius floating-point fields in this unit:
we compare each float using EqualityEpsilon,
i.e. if the difference is < EqualityEpsilon then the floats
are assumed equal. Pass EqualityEpsilon = 0.0
to perform *exact* comparison (this case will be optimized
in implementation, by using routines like CompareMem
instead of comparing float-by-float).
Note that this *doesn't* compare the default values of two fields
instances. This compares only the current values of two fields
instances, and eventually some other properties that affect
parsing (like names for TSFEnum and TSFBitMask) or allowed
future values (like TSFFloat.MustBeNonnegative).
}
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; virtual; reintroduce;
{ Compare value of this field, with other field, fast.
This compares only the values of the fields, not other properties
(it doesn't care about names of the fields or such, or default values;
only current values). In other words, it compares only the things
copied by AssignValue.
This tries to compare very fast, which means that for large
(multi-valued) fields it may give up and answer @false even
when they are in fact equal. So this is usable only for optimization
purposes: when it answers @true, it is @true. When it answers @false,
it actually doesn't know.
Default implementation in this class (@classname) just returns @false. }
function FastEqualsValue(SecondValue: TX3DField): boolean; virtual;
{ Does this field generate/accept events, that is
an "exposedField" (in VRML 2.0) or "inputOutput" (in X3D). }
property Exposed: boolean read FExposed write SetExposed default true;
{ These are the set_xxx and xxx_changed events exposed by this field.
@nil if Exposed is @false. }
property ExposedEvents [InEvent: boolean]: TX3DEvent
read GetExposedEvents;
{ Exposed events of this field. @nil if this field is not exposed.
EventIn is always equivalent to ExposedEvents[true],
EventOut is always equivalent to ExposedEvents[false].
@groupBegin }
function EventIn: TX3DEvent;
function EventOut: TX3DEvent;
{ @groupEnd }
{ When @true (default) we will automatically handle exposed events
behavior. This means that we will listen on EventIn,
and when something will be received we will set current field's value
and produce appropriate EventOut.
You almost certainly want to leave this as @true in all typical
situations, as it takes care of implementing required exposed events
behavior.
That said, in special cases you may decide to break this. }
property ExposedEventsLinked: boolean
read FExposedEventsLinked write SetExposedEventsLinked
default true;
{ Field type name in VRML/X3D.
As for VRML/X3D interface declaration statements.
In base TX3DField class, this teturns @code(XFAny)
(name indicating any type, used by instantreality and us). }
class function TypeName: string; virtual;
{ Create TX3DEvent descendant suitable as exposed event for this field. }
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; virtual;
{ Copies the current field value. Contrary to TPersistent.Assign, this
doesn't copy the rest of properties.
After setting, our ValueFromIsClause is always changed to @false.
You can manually change it to @true, if this copy indeed was done
following "IS" clause.
@raises(EX3DFieldAssignInvalidClass
Usually it's required the Source class to be equal to our class,
if Source classes cannot be assigned we raise EX3DFieldCannotAssignClass.)
@raises(EX3DFieldAssign
Raised in case of any field assignment problem. It's guaranteed that
in case of such problem, our value will not be modified before
raising the exception.
EX3DFieldAssignInvalidClass inherits from EX3DFieldAssign,
so actually EX3DFieldAssignInvalidClass is just a special case of this
exceptiion.)
@italic(Descendants implementors notes):
In this class, implementation takes care of
setting our ValueFromIsClause to @false. In descendants,
you should do like
@longCode(#
if Source is <appropriate class> then
begin
inherited;
Value := Source.value;
end else
AssignValueRaiseInvalidClass(Source);
#)
}
procedure AssignValue(Source: TX3DField); virtual;
{ Set field's default value from the current value.
Note that for now this doesn't guarantee that every possible field's value
can be stored as default value. In case of trouble, it will silently
record "no default is known" information, so e.g. EqualsDefaultValue
will always return @false.
Our default value mechanisms are sometimes
limited, not every value can be a default value. For example,
for multiple-valued nodes, we usually cannot save arrays longer than
one as default value. This is not a problem, since X3D specification
doesn't specify too long default values. But it may be a problem
for prototypes, since then user can assign any value as default value.
May be corrected in the future. }
procedure AssignDefaultValueFromValue; virtual;
{ Assigns value to this node calculated from linear interpolation
between two given nodes Value1, Value2. Just like other lerp
functions in our units (like @link(CastleVectors.Lerp)).
Like AssignValue, this copies only the current value.
All other properties (like Name, IsClauseNames, ValueFromIsClause,
default value) are untouched.
There are some special precautions for this:
@unorderedList(
@item(First of all, AssignLerp is defined only for fields where
CanAssignLerp returns @true, so always check CanAssignLerp first.
All float-based VRML fields should have this implemented.)
@item(Use this only if Value1 and Value2
are equal or descendant of target (Self) class.)
@item(For multiple-value fields, counts of Value1 and Value2
must be equal, or EX3DMultFieldDifferentCount will be raised.)
)
@raises(EX3DMultFieldDifferentCount When field is multiple-value
VRML field and Value1.Count <> Value2.Count.)
}
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); virtual;
{ @abstract(Is AssignLerp usable on this field type?)
@italic(Descendants implementors notes):
In this class, this always returns @false. }
function CanAssignLerp: boolean; virtual;
procedure AddAlternativeName(const AlternativeName: string;
VrmlMajorVersion: Integer); override;
{ Notify ParentNode.Scene that the value of this field changed. }
procedure Changed;
{ What always happens when the value of this field changes.
This is included in the @link(ExecuteChanges) method result. So instead of
using this property, you could always override @link(ExecuteChanges)
method. But often it's easier to use the property.
By default this is an empty set. This is suitable for
things that aren't *directly* an actual content (but only an
intermediate value to change other stuff). This includes
all metadata fields and nodes, all fields in event utilities,
Script node, interpolators...
See TX3DChange for possible values. }
property ChangesAlways: TX3DChanges read FChangesAlways write FChangesAlways;
{ What happens when the value of this field changes.
This is called, exactly once, by TCastleSceneCore.ChangedField
to determine what must be done when we know that value of this field changed.
In overridden descendants, this can also do something immediately.
Overriding this is similar to registering your callback in OnReceive
list, with two benefits:
@orderedList(
@item(This method may be not called (although no guarantees)
when the actual field value did not change.
In contrast, the OnReceive event is always fired,
even when you send the same value to an exposed field,
because VRML/X3D events and routes must be fired anyway.)
@item(This is useful also for fields that are not exposed,
and can be changed only by ObjectPascal code.)
)
So overridding this is closer to "do something when field value changes"
than registering callback in OnReceive list. }
function ExecuteChanges: TX3DChanges; virtual;
{ Set the value of the field, notifying the scenes and events engine.
This sets the value of this field in the nicest possible way for
any possible TCastleSceneCore (with events on or off) containing the node
with this field.
Precise specification:
@unorderedList(
@item(If this is an exposed field and we have events engine working:
We will send this value through
it's input event. In this case, this is equivalent to doing
@code(EventIn.Send(Value, Scene.Time)).
The scenes (including events engine) will be notified correctly
by exposed events handler already.)
@item(Otherwise, we will just set the fields value.
And then notify the scenes (including events engine).)
) }
procedure Send(Value: TX3DField);
{ Notifications when exposed field received new value through VRML/X3D event.
Only for exposed fields (@nil for not exposed fields).
This is simply a shortcut for @code(EventOut.OnReceive),
see TX3DEvent.OnReceive for details how does this work.
Note that this observes the "out" event (not the "in" event).
This way you know inside the handler that the field value is already
changed as appropriate. Inside "in" event handlers, you would not
know this (it would depend on the order in which handlers are run,
one "in" handler sets the field value).
Note that "out" event handlers are executed before Scene is notified
about the field value change (before TCastleSceneCore.ChangedField is called).
This is also usually exactly what you want --- you can change the scene
graph inside the event handler (for example, load something on
Inline.load or Inline.url changes), and let the TX3DField.ChangesAlways
cause appropriate action on this change. }
function OnReceive: TX3DEventReceiveList;
end;
TX3DFieldList = class(specialize TFPGObjectList<TX3DField>)
private
function GetByName(const AName: string): TX3DField;
public
{ Access field by name.
Raises EX3DNotFound if the given Name doesn't exist. }
property ByName[const AName: string]:TX3DField read GetByName;
{ Searches for a field with given Name, returns it's index or -1 if not found. }
function IndexOf(const AName: string): integer;
{ Returns if EventName is an event implicitly exposed by one of our
exposed fields (i.e. set_xxx or xxx_changed). If yes, then
returns index of event, and the event reference itself
(so always @code(Fields[ReturnedIndex].ExposedEvent[ReturnedEvent.InEvent]
= ReturnedEvent)). Otherwise, returns -1. }
function IndexOfExposedEvent(const EventName: string;
out Event: TX3DEvent): Integer;
end;
TX3DSingleField = class(TX3DField)
end;
TX3DSingleFieldClass = class of TX3DSingleField;
TX3DSingleFieldList = specialize TFPGObjectList<TX3DSingleField>;
EX3DMultFieldDifferentCount = class(Exception);
TX3DMultField = class(TX3DField)
protected
{ Get or set the number of items, see @link(Count).
@groupBegin }
function GetCount: Integer; virtual; abstract;
procedure SetCount(const Value: Integer); virtual; abstract;
{ @groupEnd }
public
{ Number of items in this field.
Remember that increasing this generally sets new items to undefined
values (see SetCount documentation of particular descendant for docs).
So you usually want to initialize them afterwards to something correct. }
property Count: Integer read GetCount write SetCount;
{ If SecondValue.Count <> Count, raises EX3DMultFieldDifferentCount }
procedure CheckCountEqual(SecondValue: TX3DMultField);
end;
{ Field holding multiple values. Remember that such field may always have
any number of items, including zero.
Note that we keep MF fields contents in TFPSList or TCastleStringList instances
(RawItems in this class, also accessible as Items (with more concrete
class) in descendants). This means that they are in compact form,
easy for reading, or even for feeding the list into OpenGL.
That's the main reason why I did not simply implement
TX3DSimpleMultField as a descendant of TX3DSingleFieldsList:
A long list of vertexes, MFVec3f, would be kept as a list of pointers
to a lot of TSFVec3f instances. This would be quite memory-consuming,
and very uncomfortable for access. On the contrary, current implementation
keeps all these vertexes inside one TVector3SingleList instance,
that internally keeps all items in one continuos piece of memory.
@italic(Descendants implementors notes): to make new descendant:
@unorderedList(
@item(In CreateUndefined you have to initialize FItemClass and create
RawItems. In destructor of this class, RawItems are freed, so
don't worry about this.)
@item(Override RawItemsAdd.)
@item(
If your ItemClass doesn't work 100% correctly when it's initialized
by CreateUndefined, you may have to override CreateItemBeforeParse.
Fortunately, VRML specification was careful to choose as multi-valued field
types' only fields that can behave nicely when initialized by
CreateUndefined (and in fact VRML 2.0 removed the "bad fields" entirely).)
@item(Not strictly required, but usually it's comfortable to have
a constructor that allows you to init default field value
from some "array of TXxx".)
) }
TX3DSimpleMultField = class(TX3DMultField)
private
InvalidIndexWarnings: Cardinal;
protected
fItemClass: TX3DSingleFieldClass;
{ This creates new instance of class ItemClass. It doesn't have to
have initialized value (in other words, it can be created by
CreateUndefined), since we'll call his Parse method immediately.
Default implementation in this class uses simply ItemClass.CreateUndefined. }
function CreateItemBeforeParse: TX3DSingleField; virtual;
{ Add Item at the end of RawItems. It's guaranteed that Item
passes here will be of class ItemClass. You should copy
Item contents as appropriate (remember that Item instance itself
may be freed soon, so copy contents, not only some reference). }
procedure RawItemsAdd(Item: TX3DSingleField); virtual abstract;
procedure OnWarning_InvalidIndex(const Index, ACount: Integer);
protected
{ SaveToStreamValue overriden for MF fields. This class handles
SaveToStreamValue fully, no need to override it again in
descendants. }
procedure SaveToStreamValue(Writer: TX3DWriter); override;
{ RawItemToString(i) must change RawItems[i] into a string that can be used to
store this is text stream. In descendants, you have to override this. }
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; virtual; abstract;
{ This says when we should do newline when writing this field into a stream.
It's has purely aesthetical meaning, nothing more.
In this class SaveToStreamDoNewLineAfterRawItem always returns @true
(although SaveToStreamValue may sometimes ignore it, if it knows better). }
function SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean; virtual;
{ Get or set the number of items.
In TX3DSimpleMultField descendants, these simply get/set RawItems.Count
(you could do it directly as well, since operating on RawItems directly
is Ok).
@groupBegin }
function GetCount: Integer; override;
procedure SetCount(const Value: Integer); override;
{ @groupEnd }
procedure Clear;
public
{ Items of this field. Either TFPSList or TCastleStringList.
@italic(Descendants implementors notes): You have to initialize this field
in descendants' constructor, it will be always freed in our
destructor. }
RawItems: TObject;
{ A corresponding SF field class. All items that will be passed
to RawItemsAdd will be of this class. }
property ItemClass: TX3DSingleFieldClass read fItemClass;
{ Parse MF field. This class handles parsing fully, usually no need to
override this more in descendants. It uses ItemClass.Parse method. }
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
destructor Destroy; override;
{ Checks equality between this and SecondValue field.
In addition to inherited(Equals), this also checks that
Count and ItemClass are equal. All descendants must check
for equality every item on SecondValue.Items[I] and Items[I]. }
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure ParseXMLAttributeLexer(Lexer: TX3DLexer; Reader: TX3DReader); override;
end;
{ ---------------------------------------------------------------------------- }
{ @section(Single value (SF) VRML fields) }
{ SFBitMask VRML 1.0 field.
TSFBitMask is one of the exceptional field types that cannot
be 100% correctly initialized by CreateUndefined, since
EnumNames will be left undefined. }
TSFBitMask = class(TX3DSingleField)
private
fAllString, fNoneString: string;
fFlagNames: TStringList;
{ Value of this field, as a bit mask.
VRML 1.0 specification guarantees that SFBitMask has 32 or less flags.
Actually, defined field values have no more than 3 fields, and
VRML > 1.0 dropped SFBitMask entirely. So 32 is always enough. }
fFlags: set of 0..31;
function GetFlags(i: integer): boolean;
procedure SetFlags(i: integer; value: boolean);
function GetFlagNames(i: integer): string;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
{ Value of this field. You can use Index from the range 0 .. FlagsCount - 1. }
property Flags[i: integer]:boolean read GetFlags write SetFlags;
function FlagsCount: integer;
property FlagNames[i: integer]:string read GetFlagNames;
{ Special strings that will be understood by parser as ALL or NONE
bit values. AllString selects all flags, NoneString selects none.
AllString may be '' is there's no such string, NoneString
should never be '' (otherwise, user could not be able to specify
some SFBitMask values --- NoneString is the only way to specify 0).
There is usually little sense in using them like "ALL | something"
(because it means just "ALL") or "NONE | something" (because it means
just "something"). But it's allowed syntactically.
@groupBegin }
property AllString: string read fAllString;
property NoneString: string read fNoneString;
{ @groupEnd }
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
{ Are all flag values set to @true currently. }
function AreAllFlags(value: boolean): boolean;
{ Constructor.
Remember that arrays AFlagNames and AFlags
(AFlags is initial value of Flags) must have equal length.
Eventually, AFlags may be longer (excessive items will be ignored). }
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AFlagNames: array of string;
const ANoneString, AAllString: string; const AFlags: array of boolean);
destructor Destroy; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
class function TypeName: string; override;
end;
TSFBool = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: boolean;
DefaultValue: boolean;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: boolean);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: boolean); overload;
end;
{ SFEnum VRML 1.0 field.
TSFEnum is one of the exceptional field types that cannot
be 100% correctly initialized by CreateUndefined, since
EnumNames will be left undefined. }
TSFEnum = class(TX3DSingleField)
private
fEnumNames: TStringList;
function GetEnumNames(i: integer): string;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
{ Value between 0 .. EnumCount - 1. By default 0. }
Value: integer;
DefaultValue: integer;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const AEnumNames: array of string; const AValue: integer);
destructor Destroy; override;
property EnumNames[i: integer]:string read GetEnumNames;
function EnumNamesCount: integer;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
procedure Send(const AValue: LongInt); overload;
end;
TSFFloat = class(TX3DSingleField)
private
FMustBeNonnegative: boolean;
FValue: Single;
FAngle: boolean;
procedure SetValue(const AValue: Single);
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
DefaultValue: Single;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Single); overload;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Single;
AMustBeNonnegative: boolean); overload;
property Value: Single read FValue write SetValue;
{ If @true then when trying to set Value to something < 0,
we'll negate it (in other words, we'll keep Value >= 0 always).
This is nice e.g. for Sphere.FdRadius field --- some incorrect VRML specify
negative sphere radius. }
property MustBeNonnegative: boolean read FMustBeNonnegative default false;
{ Value represents an angle. When reading from X3D 3.3 file, we will
make sure it's expressed in radians, honoring optional "UNIT angle ..."
declaration in X3D file. }
property Angle: boolean read FAngle write FAngle default false;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: Single); overload;
end;
{ VRML/X3D field holding a double-precision floating point value. }
TSFDouble = class(TX3DSingleField)
private
FValue: Double;
FAngle: boolean;
procedure SetValue(const AValue: Double);
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
DefaultValue: Double;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Double);
property Value: Double read FValue write SetValue;
{ Value represents an angle. When reading from X3D 3.3 file, we will
make sure it's expressed in radians, honoring optional "UNIT angle ..."
declaration in X3D file. }
property Angle: boolean read FAngle write FAngle default false;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: Double); overload;
end;
TSFTime = class(TSFDouble)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
end;
TSFImage = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
{ Value is owned by this object - i.e. in destructor we do Value.Free.
Value may be IsEmpty, and then we know that there is no image
recorded in this field. Value may never be nil.
Remember --- Value is freed by this object, but if you're altering it in any
other way, you're responsible for good memory managing. }
Value: TCastleImage;
{ @param(AValue is the initial value for Value.
Note - our constructor COPIES passed reference AValue, not it's contents
(I mean, we do Value := AValue, NOT Value := ImageCopy(AValue),
so don't Free image given to us (at least, don't do this without clearing
our Value field)).
You can pass AValue = nil, then Value will be inited to null image
TRGBImage.Create.) }
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TCastleImage);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
destructor Destroy; override;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
end;
TSFLong = class(TX3DSingleField)
private
FMustBeNonnegative: boolean;
FValue: Longint;
procedure SetValue(const AValue: Longint);
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
DefaultValue: Longint;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Longint); overload;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Longint;
AMustBeNonnegative: boolean); overload;
property Value: Longint read FValue write SetValue;
{ See TSFFloat.MustBeNonnegative for explanation of this. }
property MustBeNonnegative: boolean read FMustBeNonnegative default false;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: LongInt); virtual; overload;
end;
TSFInt32 = class(TSFLong)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: LongInt); override;
end;
TSFMatrix3f = class(TX3DSingleField)
private
FValue: TMatrix3Single;
DefaultValue: TMatrix3Single;
DefaultValueExists: boolean;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TMatrix3Single);
property Value: TMatrix3Single read FValue write FValue;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TMatrix3Single); overload;
end;
TSFMatrix3d = class(TX3DSingleField)
private
FValue: TMatrix3Double;
DefaultValue: TMatrix3Double;
DefaultValueExists: boolean;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TMatrix3Double);
property Value: TMatrix3Double read FValue write FValue;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TMatrix3Double); overload;
end;
TSFMatrix4f = class(TX3DSingleField)
private
FValue: TMatrix4Single;
DefaultValue: TMatrix4Single;
DefaultValueExists: boolean;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TMatrix4Single);
property Value: TMatrix4Single read FValue write FValue;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
{ Return average scale for current matrix Value.
Note that this doesn't correctly extract scale from matrix,
as that is too difficcult. Insted it does simple extraction,
which will work for identity, translation and scaling matrices
(but e.g. will fail miserably (generate nonsense results) when
looking at some rotation matrices). }
function TransformScale: Single;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TMatrix4Single); virtual; overload;
end;
{ VRML 1.0 SFMatrix field. }
TSFMatrix = class(TSFMatrix4f)
public
class function TypeName: string; override;
procedure Send(const AValue: TMatrix4Single); override;
end;
TSFMatrix4d = class(TX3DSingleField)
private
FValue: TMatrix4Double;
DefaultValue: TMatrix4Double;
DefaultValueExists: boolean;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TMatrix4Double);
property Value: TMatrix4Double read FValue write FValue;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TMatrix4Double); overload;
end;
TSFRotation = class(TX3DSingleField)
private
DefaultAxis: TVector3Single;
DefaultRotationRad: Single;
DefaultValueExists: boolean;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
function GetValue: TVector4Single;
procedure SetValue(const AValue: TVector4Single);
function GetValueDeg: TVector4Single;
procedure SetValueDeg(const AValue: TVector4Single);
public
Axis: TVector3Single;
RotationRad: Single;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const AnAxis: TVector3Single; const ARotationRad: Single); overload;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const AValue: TVector4Single); overload;
{ Current rotation value, with last component expressing rotation in radians.
This internally gets / sets values from @link(Axis), @link(RotationRad),
it only presents them to you differently. }
property Value: TVector4Single read GetValue write SetValue;
{ Current rotation value, with last component expressing rotation in degrees.
So this is just like @link(Value), but last component is in degrees.
This internally gets / sets values from @link(Axis), @link(RotationRad),
it only presents them to you differently. }
property ValueDeg: TVector4Single read GetValueDeg write SetValueDeg;
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
{ Rotate point Pt around Self. }
function RotatedPoint(const pt: TVector3Single): TVector3Single;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function EqualsDefaultValue: boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector4Single); overload;
end;
TSFString = class(TX3DSingleField)
private
FValue: string;
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
DefaultValue: string;
DefaultValueExists: boolean;
property Value: string read FValue write FValue;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: string);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;
function SaveToXmlValue: TSaveToXmlMethod; override;
procedure Send(const AValue: string); overload;
end;
TSFVec2f = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector2Single;
DefaultValue: TVector2Single;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector2Single);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector2Single); overload;
end;
TSFVec3f = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector3Single;
DefaultValue: TVector3Single;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector3Single);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector3Single); virtual; overload;
{ Change only a given component of the vector. }
procedure Send(const Index: Integer; const ComponentValue: Single); overload;
end;
TSFColor = class(TSFVec3f)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector3Single); override;
end;
TSFVec4f = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector4Single;
DefaultValue: TVector4Single;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector4Single);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector4Single); virtual; overload;
end;
TSFColorRGBA = class(TSFVec4f)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector4Single); override;
end;
TSFVec2d = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector2Double;
DefaultValue: TVector2Double;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector2Double);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector2Double); overload;
end;
TSFVec3d = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector3Double;
DefaultValue: TVector3Double;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector3Double);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector3Double); overload;
end;
TSFVec4d = class(TX3DSingleField)
protected
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
Value: TVector4Double;
DefaultValue: TVector4Double;
DefaultValueExists: boolean;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TVector4Double);
procedure ParseValue(Lexer: TX3DLexer; Reader: TX3DReader); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
function FastEqualsValue(SecondValue: TX3DField): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: TVector4Double); overload;
end;
{ ---------------------------------------------------------------------------- }
{ @section(Multiple value (MF) VRML fields)
General implementation comments for MF fields:
Field DefaultValuesCount may have three valid values (for now):
-1 (means "no default value for this field")
0 (means "default value of this field is empty")
1 (means "default value of this field is one-item array with DefaultValue").
As you can see, it's not possible to express default values with more
than one item. That's OK, because nodes from VRML 1.0 and 2.0 specifications
never have such field (and VRML 2.0 prototypes (that have user-defined
default field values) actually don't need it). So, for now, more flexible
DefaultValuesCount is not needed.
CreateUndefined sets DefaultValuesCount to -1.
}
{ }
TMFBool = class(TX3DSimpleMultField)
private
DefaultValuesCount: Integer;
DefaultValue: boolean;
function GetItems: TBooleanList;
procedure SetItems(const Value: TBooleanList);
function GetItemsSafe(Index: Integer): boolean;
procedure SetItemsSafe(Index: Integer; const Value: boolean);
protected
function RawItemToString(ItemNum: Integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TBooleanList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const InitialContent: array of boolean);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return false, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: boolean
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of boolean); overload;
end;
TMFLong = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: Longint;
FSaveToStreamLineUptoNegative: boolean;
WrongVertexIndexWarnings: Integer;
function GetItemsSafe(Index: Integer): LongInt;
procedure SetItemsSafe(Index: Integer; const Value: LongInt);
function GetItems: TLongIntList;
procedure SetItems(const Value: TLongIntList);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
function SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean; override;
public
{ When saving to VRML/X3D classic encoding,
make newline after each negative value on the list.
This makes a nice output for fields like IndexedFaceSet.coordIndex. }
property SaveToStreamLineUptoNegative: boolean
read FSaveToStreamLineUptoNegative write FSaveToStreamLineUptoNegative
default false;
property Items: TLongintList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of Longint);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: LongInt
read GetItemsSafe write SetItemsSafe;
{ Call OnWarning reporting that an invalid vertex index
is caused from this field. This simply calls OnWarning
formatting appropriate message.
Additionally this guards
us against producing too many warnings from the same field.
When a given threshold will be reached, further
OnWarning_WrongVertexIndex calls for this field instance
will be simply ignored. This is a good thing, as some invalid models
have really an incredible amount of invalid indexes, and the very
amount of lines printed on console makes viewing these invalid files
(at least, the valid parts of them) impossible.
Example test cases:
content/examples/Basic/HumanoidAnimation/AllenStandShootRifleM24.x3d
and
content/examples/Basic/HumanoidAnimation/NancyDiving.x3dv
from http://www.web3d.org/ example models. }
procedure OnWarning_WrongVertexIndex(
const GeometryNodeTypeName: string;
const VertexNum: Integer; const CoordCount: Integer);
procedure Send(const AValue: array of LongInt); virtual; overload;
end;
TMFInt32 = class(TMFLong)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: array of LongInt); override;
end;
TMFMatrix3f = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TMatrix3Single;
function GetItems: TMatrix3SingleList;
procedure SetItems(const Value: TMatrix3SingleList);
function GetItemsSafe(Index: Integer): TMatrix3Single;
procedure SetItemsSafe(Index: Integer; const Value: TMatrix3Single);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TMatrix3SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TMatrix3Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return identity matrix, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TMatrix3Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TMatrix3Single); overload;
end;
TMFMatrix3d = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TMatrix3Double;
function GetItems: TMatrix3DoubleList;
procedure SetItems(const Value: TMatrix3DoubleList);
function GetItemsSafe(Index: Integer): TMatrix3Double;
procedure SetItemsSafe(Index: Integer; const Value: TMatrix3Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TMatrix3DoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TMatrix3Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return identity matrix, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TMatrix3Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TMatrix3Double); overload;
end;
TMFMatrix4f = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TMatrix4Single;
function GetItems: TMatrix4SingleList;
procedure SetItems(const Value: TMatrix4SingleList);
function GetItemsSafe(Index: Integer): TMatrix4Single;
procedure SetItemsSafe(Index: Integer; const Value: TMatrix4Single);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TMatrix4SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TMatrix4Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return identity matrix, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TMatrix4Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TMatrix4Single); overload;
end;
TMFMatrix4d = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TMatrix4Double;
function GetItems: TMatrix4DoubleList;
procedure SetItems(const Value: TMatrix4DoubleList);
function GetItemsSafe(Index: Integer): TMatrix4Double;
procedure SetItemsSafe(Index: Integer; const Value: TMatrix4Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TMatrix4DoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TMatrix4Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return identity matrix, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TMatrix4Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TMatrix4Double); overload;
end;
TMFVec2f = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector2Single;
function GetItemsSafe(Index: Integer): TVector2Single;
procedure SetItemsSafe(Index: Integer; const Value: TVector2Single);
function GetItems: TVector2SingleList;
procedure SetItems(const Value: TVector2SingleList);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector2SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector2Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero vector, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector2Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector2Single); overload;
end;
TMFVec3f = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector3Single;
function GetItemsSafe(Index: Integer): TVector3Single;
procedure SetItemsSafe(Index: Integer; const Value: TVector3Single);
function GetItems: TVector3SingleList;
procedure SetItems(const Value: TVector3SingleList);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector3SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector3Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero vector, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector3Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector3Single); virtual; overload;
end;
TMFColor = class(TMFVec3f)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: array of TVector3Single); override;
end;
TMFVec4f = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector4Single;
function GetItemsSafe(Index: Integer): TVector4Single;
procedure SetItemsSafe(Index: Integer; const Value: TVector4Single);
function GetItems: TVector4SingleList;
procedure SetItems(const Value: TVector4SingleList);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector4SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector4Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return (0, 0, 0, 1) vector, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector4Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector4Single); virtual; overload;
end;
TMFColorRGBA = class(TMFVec4f)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure Send(const AValue: array of TVector4Single); override;
end;
TMFVec2d = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector2Double;
function GetItems: TVector2DoubleList;
procedure SetItems(const Value: TVector2DoubleList);
function GetItemsSafe(Index: Integer): TVector2Double;
procedure SetItemsSafe(Index: Integer; const Value: TVector2Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector2DoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector2Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero vector, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector2Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector2Double); overload;
end;
TMFVec3d = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector3Double;
function GetItems: TVector3DoubleList;
procedure SetItems(const Value: TVector3DoubleList);
function GetItemsSafe(Index: Integer): TVector3Double;
procedure SetItemsSafe(Index: Integer; const Value: TVector3Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector3DoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector3Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero vector, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector3Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector3Double); overload;
end;
TMFVec4d = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: TVector4Double;
function GetItems: TVector4DoubleList;
procedure SetItems(const Value: TVector4DoubleList);
function GetItemsSafe(Index: Integer): TVector4Double;
procedure SetItemsSafe(Index: Integer; const Value: TVector4Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector4DoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of TVector4Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return (0, 0, 0, 1), Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector4Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector4Double); overload;
end;
TMFRotation = class(TX3DSimpleMultField)
private
DefaultValuesCount: Integer;
DefaultValue: TVector4Single;
function GetItems: TVector4SingleList;
procedure SetItems(const Value: TVector4SingleList);
function GetItemsSafe(Index: Integer): TVector4Single;
procedure SetItemsSafe(Index: Integer; const Value: TVector4Single);
protected
function RawItemToString(ItemNum: Integer; const Encoding: TX3DEncoding): string; override;
public
property Items: TVector4SingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const InitialContent: array of TVector4Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return DefaultRotation, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: TVector4Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of TVector4Single); overload;
end;
TMFFloat = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: Single;
FAngle: boolean;
function GetItems: TSingleList;
procedure SetItems(const Value: TSingleList);
function GetItemsSafe(Index: Integer): Single;
procedure SetItemsSafe(Index: Integer; const Value: Single);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
function SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean; override;
function CreateItemBeforeParse: TX3DSingleField; override;
public
{ Value represents an angle. When reading from X3D 3.3 file, we will
make sure it's expressed in radians, honoring optional "UNIT angle ..."
declaration in X3D file. }
property Angle: boolean read FAngle write FAngle default false;
property Items: TSingleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const InitialContent: array of Single);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: Single
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of Single); overload;
end;
TMFDouble = class(TX3DSimpleMultField)
private
DefaultValuesCount: integer;
DefaultValue: Double;
function GetItems: TDoubleList;
procedure SetItems(const Value: TDoubleList);
function GetItemsSafe(Index: Integer): Double;
procedure SetItemsSafe(Index: Integer; const Value: Double);
protected
function RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string; override;
function SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean; override;
public
property Items: TDoubleList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string;
const InitialContent: array of Double);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure AssignLerp(const A: Double; Value1, Value2: TX3DField); override;
function CanAssignLerp: boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return zero, Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: Double
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of Double); overload;
end;
TMFTime = class(TMFDouble)
public
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
end;
TMFString = class(TX3DSimpleMultField)
private
DefaultValuesCount: Integer;
DefaultValue: string;
function GetItems: TCastleStringList;
procedure SetItems(const Value: TCastleStringList);
function GetItemsSafe(Index: Integer): string;
procedure SetItemsSafe(Index: Integer; const Value: string);
protected
function RawItemToString(ItemNum: Integer; const Encoding: TX3DEncoding): string; override;
procedure SaveToStreamValue(Writer: TX3DWriter); override;
public
property Items: TCastleStringList read GetItems write SetItems;
procedure RawItemsAdd(Item: TX3DSingleField); override;
constructor Create(AParentNode: TX3DFileItem;
const AName: string; const InitialContent: array of string);
constructor CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean); override;
function EqualsDefaultValue: boolean; override;
function Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean; override;
procedure Assign(Source: TPersistent); override;
procedure AssignValue(Source: TX3DField); override;
procedure AssignDefaultValueFromValue; override;
class function TypeName: string; override;
class function CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent; override;
procedure ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader); override;
function SaveToXmlValue: TSaveToXmlMethod; override;
{ Access Items[] checking for range errors.
In case of errors, Get will return '', Set will do nothing,
and both will produce clear OnWarning. }
property ItemsSafe[Index: Integer]: string
read GetItemsSafe write SetItemsSafe;
procedure Send(const AValue: array of string); overload;
end;
{ Stores information about available VRML/X3D field classes.
The only use for now is to make a mapping from VRML/X3D field name to
actual class (needed by VRML/X3D interface declarations). }
TX3DFieldsManager = class
private
Registered: TStringList;
public
constructor Create;
destructor Destroy; override;
procedure RegisterClass(AClass: TX3DFieldClass);
procedure RegisterClasses(const Classes: array of TX3DFieldClass);
{ Return field class for given name. Returns @nil if not found. }
function FieldTypeNameToClass(const TypeName: string): TX3DFieldClass;
end;
{$I x3devents.inc}
{$I x3devents_descendants.inc}
function X3DFieldsManager: TX3DFieldsManager;
{ Decode color from integer value, following VRML/X3D SFImage specification.
@groupBegin }
procedure DecodeImageColor(const Pixel: LongWord; var G: Byte);
procedure DecodeImageColor(const Pixel: LongWord; var GA: TVector2Byte);
procedure DecodeImageColor(const Pixel: LongWord; var RGB: TVector3Byte);
procedure DecodeImageColor(const Pixel: LongWord; var RGBA: TVector4Byte);
procedure DecodeImageColor(const Pixel: LongInt; var G: Byte);
procedure DecodeImageColor(const Pixel: LongInt; var GA: TVector2Byte);
procedure DecodeImageColor(const Pixel: LongInt; var RGB: TVector3Byte);
procedure DecodeImageColor(const Pixel: LongInt; var RGBA: TVector4Byte);
{ @groupEnd }
const
X3DChangeToStr: array [TX3DChange] of string =
( 'Visible Geometry',
'Visible Non-Geometry',
'Camera',
'Redisplay',
'Transform',
'Coordinate',
'VRML 1.0 State (but not affecting geometry or Coordinate)',
'VRML 1.0 State (affecting geometry, but not Coordinate)',
'Material',
'Blending',
'Light active property',
'Light location/direction',
'Light for shadow volumes',
'Switch choice',
'Color node',
'Texture coordinate',
'Texture transform',
'Geometry',
'Environmental sensor bounds',
'Time stop/start/pause/resume',
'Viewpoint vectors',
'Viewpoint projection',
'Texture image',
'Texture renderer properties',
'TextureProperties node',
'Shadow caster',
'Generated texture update',
'FontStyle',
'HeadLight on',
'ClipPlane',
'X3DDragSensorNode.enabled',
'NavigationInfo',
'ScreenEffect.enabled',
'Background',
'Everything',
'Shadow maps');
function X3DChangesToStr(const Changes: TX3DChanges): string;
{$undef read_interface}
implementation
uses Math, X3DNodes, CastleXMLUtils, CastleWarnings;
{$define read_implementation}
{$I x3devents.inc}
{$I x3devents_descendants.inc}
{ TX3DWriter ----------------------------------------------------------------- }
const
{ IndentIncrement is string or char. It's used by SaveToStream }
IndentIncrement = CharTab;
constructor TX3DWriter.Create(AStream: TStream; const AVersion: TX3DVersion;
const AEncoding: TX3DEncoding);
begin
inherited Create;
Version := AVersion;
FStream := AStream;
FEncoding := AEncoding;
end;
destructor TX3DWriter.Destroy;
begin
inherited;
end;
procedure TX3DWriter.IncIndent;
var
L: Integer;
begin
L := Length(Indent) + 1;
SetLength(Indent, L);
Indent[L] := IndentIncrement;
end;
procedure TX3DWriter.DecIndent;
begin
SetLength(Indent, Length(Indent) - 1);
end;
procedure TX3DWriter.Write(const S: string);
begin
WriteStr(FStream, S);
end;
procedure TX3DWriter.Writeln(const S: string);
begin
WriteStr(FStream, S);
WriteStr(FStream, NL);
end;
procedure TX3DWriter.Writeln;
begin
WriteStr(FStream, NL);
end;
procedure TX3DWriter.WriteIndent(const S: string);
begin
if DoDiscardNextIndent then
DoDiscardNextIndent := false else
WriteStr(FStream, Indent);
WriteStr(FStream, S);
end;
procedure TX3DWriter.WritelnIndent(const S: string);
begin
WriteIndent(S);
WriteStr(FStream, NL);
end;
procedure TX3DWriter.DiscardNextIndent;
begin
DoDiscardNextIndent := true;
end;
{ TX3DReader ----------------------------------------------------------------- }
constructor TX3DReader.Create(
const ABaseUrl: string; const AVersion: TX3DVersion);
begin
inherited Create;
FBaseUrl := ABaseUrl;
FVersion := AVersion;
AngleConversionFactor := 1;
LengthConversionFactor := 1;
end;
constructor TX3DReader.CreateCopy(Source: TX3DReader);
begin
inherited Create;
FBaseUrl := Source.BaseUrl;
FVersion := Source.Version;
AngleConversionFactor := Source.AngleConversionFactor;
LengthConversionFactor := Source.LengthConversionFactor;
end;
procedure TX3DReader.UnitConversion(const Category, Name: string;
const ConversionFactor: Float);
begin
if (Version.Major < 3) or
( (Version.Major = 3) and
(Version.Minor < 3) ) then
OnWarning(wtMajor, 'X3D', 'UNIT declaration found, but X3D version is < 3.3');
{ store UNIT inside Reader }
if Category = 'angle' then
AngleConversionFactor := ConversionFactor else
if Category = 'force' then
{ TODO } else
if Category = 'length' then
LengthConversionFactor := ConversionFactor else
if Category = 'mass' then
{ TODO } else
OnWarning(wtMajor, 'X3D', Format('UNIT category "%s" unknown. Only the categories listed in X3D specification as base units are allowed',
[Category]));
end;
{ TX3DFileItem -------------------------------------------------------------- }
constructor TX3DFileItem.Create;
begin
inherited;
FPositionInParent := -1;
end;
function TX3DFileItem.SaveToXml: TSaveToXmlMethod;
begin
Result := sxChildElement;
end;
{ TX3DFileItemList --------------------------------------------------------- }
function IsSmallerPositionInParent(const A, B: TX3DFileItem): Integer;
begin
Result := A.PositionInParent - B.PositionInParent;
if Result = 0 then
Result := A.PositionOnList - B.PositionOnList;
end;
procedure TX3DFileItemList.SortPositionInParent;
begin
Sort(@IsSmallerPositionInParent);
end;
procedure TX3DFileItemList.SaveToStream(Writer: TX3DWriter);
var
I: Integer;
begin
SortPositionInParent;
for I := 0 to Count - 1 do
Items[I].SaveToStream(Writer);
end;
procedure TX3DFileItemList.Add(Item: TX3DFileItem);
begin
Item.PositionOnList := Count;
inherited Add(Item);
end;
{ TX3DFieldOrEvent ---------------------------------------------------------- }
constructor TX3DFieldOrEvent.Create(AParentNode: TX3DFileItem;
const AName: string);
begin
inherited Create;
FParentNode := AParentNode;
FName := AName;
end;
destructor TX3DFieldOrEvent.Destroy;
begin
FreeAndNil(FIsClauseNames);
inherited;
end;
function TX3DFieldOrEvent.IsClauseNamesCreate: TCastleStringList;
begin
if FIsClauseNames = nil then
FIsClauseNames := TCastleStringList.Create;
Result := FIsClauseNames;
end;
function TX3DFieldOrEvent.GetIsClauseNames(const Index: Integer): string;
begin
if FIsClauseNames = nil then
raise Exception.CreateFmt('IsClauseNames item index %d does not exist, because IsClauseNames is empty',
[Index]);
Result := FIsClauseNames[Index];
end;
function TX3DFieldOrEvent.IsClauseNamesCount: Integer;
begin
if FIsClauseNames = nil then
Result := 0 else
Result := FIsClauseNames.Count;
end;
procedure TX3DFieldOrEvent.IsClauseNamesAssign(
const SourceIsClauseNames: TCastleStringList);
begin
if (SourceIsClauseNames <> nil) and
(SourceIsClauseNames.Count <> 0) then
IsClauseNamesCreate.Assign(SourceIsClauseNames) else
FreeAndNil(FIsClauseNames);
end;
procedure TX3DFieldOrEvent.IsClauseNamesAdd(const S: string);
begin
IsClauseNamesCreate.Add(S);
end;
procedure TX3DFieldOrEvent.ParseIsClause(Lexer: TX3DLexer);
begin
if Lexer.TokenIsKeyword(vkIS) then
begin
Lexer.NextToken;
IsClauseNamesCreate.Add(Lexer.TokenName);
Lexer.NextToken;
end;
end;
procedure TX3DFieldOrEvent.AddAlternativeName(const AlternativeName: string;
VrmlMajorVersion: Integer);
begin
FAlternativeNames[VrmlMajorVersion] := AlternativeName;
end;
function TX3DFieldOrEvent.IsName(const S: string): boolean;
var
I: Integer;
begin
{ No field is ever named ''.
Actually, we sometimes use '' for special "unnamed fields",
in this case it's Ok that no name matches their name.
Besides, we don't want empty FAlternativeNames to match when
searching for S = ''. }
if S = '' then
Exit(false);
for I := Low(FAlternativeNames) to High(FAlternativeNames) do
if FAlternativeNames[I] = S then
Exit(true);
Result := Name = S;
end;
function TX3DFieldOrEvent.NameForVersion(
Version: TX3DVersion): string;
begin
Result := FAlternativeNames[Version.Major];
if Result = '' then
Result := Name;
end;
function TX3DFieldOrEvent.NameForVersion(
Writer: TX3DWriter): string;
begin
Result := NameForVersion(Writer.Version);
end;
procedure TX3DFieldOrEvent.FieldOrEventAssignCommon(Source: TX3DFieldOrEvent);
begin
FName := Source.Name;
IsClauseNamesAssign(Source.FIsClauseNames);
FPositionInParent := Source.PositionInParent;
FAlternativeNames := Source.FAlternativeNames;
end;
function TX3DFieldOrEvent.NiceName: string;
begin
Result := '';
if ParentNode <> nil then
Result += TX3DNode(ParentNode).NiceName + '.';
if Name <> '' then
Result += Name else
Result += '<not named field>';
end;
procedure TX3DFieldOrEvent.SaveToStreamClassicIsClauses(Writer: TX3DWriter);
var
N: string;
I: Integer;
begin
N := NameForVersion(Writer);
{ When N = '', we assume that field/event has only one "IS" clause.
Otherwise results don't make any sense. }
for I := 0 to IsClauseNamesCount - 1 do
begin
if N <> '' then
Writer.WriteIndent(N + ' ');
Writer.Writeln('IS ' + IsClauseNames[I]);
end;
end;
{ TX3DField ------------------------------------------------------------- }
constructor TX3DField.Create(AParentNode: TX3DFileItem;
const AName: string);
begin
CreateUndefined(AParentNode, AName,
true { default Exposed = true for normal constructor });
end;
constructor TX3DField.CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean);
begin
inherited Create(AParentNode, AName);
FExposedEventsLinked := true;
{ Set Exposed by the property, to force FExposedEvents initialization }
FExposed := false;
Exposed := AExposed;
end;
destructor TX3DField.Destroy;
begin
FreeAndNil(FExposedEvents[false]);
FreeAndNil(FExposedEvents[true]);
inherited;
end;
function TX3DField.GetExposedEvents(InEvent: boolean): TX3DEvent;
begin
Result := FExposedEvents[InEvent];
end;
function TX3DField.EventIn: TX3DEvent;
begin
Result := FExposedEvents[true];
end;
function TX3DField.EventOut: TX3DEvent;
begin
Result := FExposedEvents[false];
end;
procedure TX3DField.ExposedEventReceive(Event: TX3DEvent; Value: TX3DField;
const Time: TX3DTime);
var
ValuePossiblyChanged: boolean;
begin
Assert(Exposed);
Assert(Event = FExposedEvents[true]);
Assert(Value is ExposedEventsFieldClass);
{ When not ValuePossiblyChanged, we don't have to call ChangedField.
(Although we still have to call FExposedEvents[false].Send,
to push the change through the routes.)
This may be an important optimization when simple field's change
causes large time-consuming work in ChangedField, e.g. consider
Switch.whichChoice which means currently rebuilding a lot of things. }
ValuePossiblyChanged := not FastEqualsValue(Value);
{ This is trivial handling of exposed events: just set our value,
and call out event. }
AssignValue(Value);
FExposedEvents[false].Send(Value, Time);
{ Tests:
if not ValuePossiblyChanged then
writeln('ignored field ', Name, ' change, since values the same'); }
if ValuePossiblyChanged then
Changed;
end;
procedure TX3DField.Changed;
var
Parent: TX3DNode;
begin
if ParentNode <> nil then
begin
Parent := ParentNode as TX3DNode;
if Parent.Scene <> nil then
Parent.Scene.ChangedField(Self);
end;
end;
function TX3DField.ExecuteChanges: TX3DChanges;
begin
Result := ChangesAlways;
end;
procedure TX3DField.Send(Value: TX3DField);
var
ValuePossiblyChanged: boolean;
begin
if Exposed and (ParentNode <> nil) and
( (ParentNode as TX3DNode).Scene <> nil ) then
begin
EventIn.Send(Value, TX3DNode(ParentNode).Scene.GetTime);
end else
begin
ValuePossiblyChanged := not FastEqualsValue(Value);
{ Call AssignValue regardless of ValuePossiblyChanged.
Reason: AssignValue also removes "IS" clause. }
AssignValue(Value);
if ValuePossiblyChanged then Changed;
end;
end;
const
SetPrefix = 'set_';
ChangedSuffix = '_changed';
procedure TX3DField.SetExposedEventsLinked(const Value: boolean);
begin
if FExposedEventsLinked <> Value then
begin
FExposedEventsLinked := Value;
if Exposed then
begin
if ExposedEventsLinked then
FExposedEvents[true].OnReceive.Add(@ExposedEventReceive) else
FExposedEvents[true].OnReceive.Remove(@ExposedEventReceive);
end;
end;
end;
class function TX3DField.ExposedEventsFieldClass: TX3DFieldClass;
begin
Result := TX3DFieldClass(ClassType);
end;
class function TX3DField.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TX3DEvent.Create(AParentNode, AName, ExposedEventsFieldClass, AInEvent);
end;
procedure TX3DField.SetExposed(Value: boolean);
var
I: Integer;
begin
if Value <> Exposed then
begin
FExposed := Value;
if Exposed then
begin
FExposedEvents[false] := CreateEvent(ParentNode, Name + ChangedSuffix, false);
FExposedEvents[false].ParentExposedField := Self;
FExposedEvents[true] := CreateEvent(ParentNode, SetPrefix + Name, true);
FExposedEvents[true].ParentExposedField := Self;
for I := Low(FAlternativeNames) to High(FAlternativeNames) do
if FAlternativeNames[I] <> '' then
begin
FExposedEvents[false].AddAlternativeName(
FAlternativeNames[I] + ChangedSuffix, I);
FExposedEvents[true].AddAlternativeName(
SetPrefix + FAlternativeNames[I], I);
end;
if ExposedEventsLinked then
FExposedEvents[true].OnReceive.Add(@ExposedEventReceive);
end else
begin
if ExposedEventsLinked then
FExposedEvents[true].OnReceive.Remove(@ExposedEventReceive);
FreeAndNil(FExposedEvents[false]);
FreeAndNil(FExposedEvents[true]);
end;
end;
end;
procedure TX3DField.FieldSaveToStream(Writer: TX3DWriter;
FieldSaveWhenDefault, XmlAvoidSavingNameBeforeValue: boolean);
var
N: string;
begin
N := NameForVersion(Writer);
if (not ValueFromIsClause) and
(FieldSaveWhenDefault or (not EqualsDefaultValue)) then
case Writer.Encoding of
xeClassic:
begin
if N <> '' then
Writer.WriteIndent(N + ' ');
SaveToStreamValue(Writer);
Writer.Writeln;
end;
xeXML:
{ for xml encoding, field must be named, unless explicitly not wanted by XmlAvoidSavingNameBeforeValue }
if (N <> '') or XmlAvoidSavingNameBeforeValue then
begin
if (SaveToXml in [sxAttribute, sxAttributeCustomQuotes]) and
(not XmlAvoidSavingNameBeforeValue) then
begin
Writer.Writeln;
Writer.WriteIndent(N + '=');
end;
if SaveToXml = sxAttribute then
Writer.Write('"');
SaveToStreamValue(Writer);
if SaveToXml = sxAttribute then
Writer.Write('"');
end;
else raise EInternalError.Create('TX3DField.FieldSaveToStream Encoding?');
end;
end;
procedure TX3DField.SaveToStream(Writer: TX3DWriter);
begin
FieldSaveToStream(Writer);
end;
function TX3DField.SaveToXmlValue: TSaveToXmlMethod;
begin
Result := sxAttribute;
end;
function TX3DField.SaveToXml: TSaveToXmlMethod;
begin
{ Detect sxNone for XML encoding, this allows better output in many cases,
also avoids <fieldValue> inside <ProtoInstance> when the field value actually
doesn't have to be specified.
When FieldSaveToStream saves field value? FieldSaveToStream checks
(not ValueFromIsClause) and
(FieldSaveWhenDefault or (not EqualsDefaultValue))
SaveToStream calls FieldSaveToStream with default FieldSaveWhenDefault = false. }
if (not ValueFromIsClause) and (not EqualsDefaultValue) then
Result := SaveToXmlValue else
Result := sxNone;
end;
function TX3DField.EqualsDefaultValue: boolean;
begin
Result := false;
end;
function TX3DField.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := SecondValue.Name = Name;
end;
function TX3DField.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := false;
end;
procedure TX3DField.Parse(Lexer: TX3DLexer; Reader: TX3DReader; IsClauseAllowed: boolean);
begin
if IsClauseAllowed and Lexer.TokenIsKeyword(vkIS) then
ParseIsClause(Lexer) else
ParseValue(Lexer, Reader);
end;
procedure TX3DField.ParseXMLAttributeLexer(Lexer: TX3DLexer; Reader: TX3DReader);
begin
ParseValue(Lexer, Reader);
end;
procedure TX3DField.ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader);
var
Lexer: TX3DLexer;
begin
Lexer := TX3DLexer.CreateForPartialStream(AttributeValue, Reader.Version);
try
try
ParseXMLAttributeLexer(Lexer, Reader);
except
on E: EX3DClassicReadError do
OnWarning(wtMajor, 'VRML/X3D', 'Error when reading field "' + Name + '" value: ' + E.Message);
end;
finally FreeAndNil(Lexer) end;
end;
procedure TX3DField.ParseXMLElement(Element: TDOMElement; Reader: TX3DReader);
var
I: TXMLElementIterator;
begin
I := TXMLElementIterator.Create(Element);
try
if I.GetNext then
OnWarning(wtMajor, 'VRML/X3D', Format('X3D field "%s" is not SFNode or MFNode, but a node value (XML element "%s") is specified',
[Name, I.Current.TagName]));
finally FreeAndNil(I) end;
end;
procedure TX3DField.VRMLFieldAssignCommon(Source: TX3DField);
var
NameChanges, ExposedChanges: boolean;
I: Integer;
begin
NameChanges := Name <> Source.Name;
ExposedChanges := Exposed <> Source.Exposed;
FieldOrEventAssignCommon(Source);
ValueFromIsClause := Source.ValueFromIsClause;
Exposed := Source.Exposed;
Assert(Exposed = (ExposedEvents[false] <> nil));
Assert(Exposed = (ExposedEvents[true] <> nil));
{ This is a little tricky: we copied Exposed value by SetExposed,
to actually create or destroy exposed events.
But note that events in
ExposedEvents have names dependent on our name. So we have to eventually
change their names too. This is not needed if exposed
changes from true->false (then events will be destroyed),
changes from false->true (then events will be created with already new names),
stays as false->false (then events don't exist).
So it's needed only when exposed was true, and stays true, but name changed.
}
if NameChanges and Exposed and (not ExposedChanges) then
begin
FExposedEvents[false].FName := Name + ChangedSuffix;
FExposedEvents[true].FName := SetPrefix + Name;
end;
Assert((not Exposed) or (FExposedEvents[false].FName = Name + ChangedSuffix));
Assert((not Exposed) or (FExposedEvents[true].FName = SetPrefix + Name));
{ Once again an issue with dependency of ExposedEvents on our name:
potentially alternative names changed,
so we have to redo this in exposed events. }
if Exposed then
begin
for I := Low(FAlternativeNames) to High(FAlternativeNames) do
if FAlternativeNames[I] <> '' then
begin
FExposedEvents[false].FAlternativeNames[I] :=
FAlternativeNames[I] + ChangedSuffix;
FExposedEvents[true].FAlternativeNames[I] :=
SetPrefix + FAlternativeNames[I];
end else
begin
FExposedEvents[false].FAlternativeNames[I] := '';
FExposedEvents[true].FAlternativeNames[I] := '';
end;
end;
end;
procedure TX3DField.AssignValueRaiseInvalidClass(Source: TX3DField);
begin
raise EX3DFieldAssignInvalidClass.CreateFmt('Cannot assign VRML/X3D field ' +
'%s (%s) from %s (%s)',
[ Name, TypeName,
Source.Name, Source.TypeName]);
end;
procedure TX3DField.AssignValue(Source: TX3DField);
begin
ValueFromIsClause := false;
end;
procedure TX3DField.AssignDefaultValueFromValue;
begin
{ do nothing in this class }
end;
procedure TX3DField.AssignLerp(const A: Double; Value1, Value2: TX3DField);
begin
{ do nothing, CanAssignLerp is false }
end;
function TX3DField.CanAssignLerp: boolean;
begin
Result := false;
end;
procedure TX3DField.AddAlternativeName(const AlternativeName: string;
VrmlMajorVersion: Integer);
begin
inherited;
if Exposed then
begin
Assert(FExposedEvents[false] <> nil);
Assert(FExposedEvents[true] <> nil);
FExposedEvents[false].AddAlternativeName(
AlternativeName + ChangedSuffix, VrmlMajorVersion);
FExposedEvents[true].AddAlternativeName(
SetPrefix + AlternativeName, VrmlMajorVersion);
end;
end;
{ Note that TX3DField.TypeName cannot be abstract:
it may be used if source event is of XFAny type in warning message
in TX3DRoute.SetEndingInternal }
class function TX3DField.TypeName: string;
begin
Result := 'XFAny';
end;
function TX3DField.OnReceive: TX3DEventReceiveList;
begin
if FExposedEvents[false] <> nil then
Result := FExposedEvents[false].OnReceive else
Result := nil;
end;
{ TX3DFieldList ------------------------------------------------------------- }
function TX3DFieldList.IndexOf(const AName: string): integer;
begin
for Result := 0 to Count-1 do
if Items[Result].IsName(AName) then
Exit;
Result := -1;
end;
function TX3DFieldList.GetByName(const AName: string): TX3DField;
var
I: integer;
begin
I := IndexOf(AName);
if I <> -1 then
Result := Items[I] else
raise EX3DNotFound.CreateFmt('Field name "%s" not found', [AName]);
end;
function TX3DFieldList.IndexOfExposedEvent(const EventName: string;
out Event: TX3DEvent): Integer;
var
InEvent: boolean;
begin
{ This implementation is quite optimized.
Instead of browsing all fields and their ExposedEvents,
looking for EventName event, instead we examine EventName
to look whether this has any chance of being set_xxx or xxx_changed
event. So we utilize the fact that exposed events have consistent
naming. }
if IsPrefix(SetPrefix, EventName, false) then
begin
InEvent := true;
Result := IndexOf(SEnding(EventName, Length(SetPrefix) + 1));
end else
if IsSuffix(ChangedSuffix, EventName, false) then
begin
InEvent := false;
Result := IndexOf(Copy(EventName, 1,
Length(EventName) - Length(ChangedSuffix)));
end else
Result := -1;
{ check is field really exposed now }
if (Result <> -1) and (not Items[Result].Exposed) then
begin
Result := -1;
end;
if Result <> -1 then
begin
Event := Items[Result].ExposedEvents[InEvent];
end;
end;
{ TX3DMultField ------------------------------------------------------------- }
procedure TX3DMultField.CheckCountEqual(SecondValue: TX3DMultField);
begin
if SecondValue.Count <> Count then
raise EX3DMultFieldDifferentCount.CreateFmt(
'Different length of multiple-value fields "%s" and "%s": "%d" and "%d"',
[ Name,
SecondValue.Name,
Count,
SecondValue.Count ]);
end;
{ TX3DSimpleMultField ------------------------------------------------------- }
destructor TX3DSimpleMultField.Destroy;
begin
RawItems.Free;
inherited;
end;
function TX3DSimpleMultField.GetCount: Integer;
begin
if RawItems is TFPSList then
Result := TFPSList(RawItems).Count else
Result := TCastleStringList(RawItems).Count;
end;
procedure TX3DSimpleMultField.SetCount(const Value: Integer);
begin
if RawItems is TFPSList then
TFPSList(RawItems).Count := Value else
TCastleStringList(RawItems).Count := Value;
end;
procedure TX3DSimpleMultField.Clear;
begin
if RawItems is TFPSList then
TFPSList(RawItems).Clear else
TCastleStringList(RawItems).Clear;
end;
function TX3DSimpleMultField.CreateItemBeforeParse: TX3DSingleField;
begin
result := ItemClass.CreateUndefined(ParentNode, '', false);
end;
procedure TX3DSimpleMultField.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
var
SingleItem: TX3DSingleField;
begin
Clear;
SingleItem := nil;
try
SingleItem := CreateItemBeforeParse;
if Lexer.Token = vtOpenSqBracket then
begin
Lexer.NextToken;
{ List size may be increased rapidly during parsing.
Prepare for it by allocating some size in advance. }
if RawItems is TFPSList then
TFPSList(RawItems).Capacity := 64;
while Lexer.Token <> vtCloseSqBracket do
{ we always look now at "]" or next single value }
begin
SingleItem.ParseValue(Lexer, Reader);
RawItemsAdd(SingleItem);
if Lexer.Token = vtCloseSqBracket then break;
if Lexer.Version.Major < 2 then
begin
Lexer.CheckTokenIs(vtComma);
Lexer.NextToken;
end;
end;
{ Our handling of commas is specified by VRML 1.0 spec:
- When the list has no items, "[]" is allowed but "[,]" is not.
- When there are some items on the list, the last item *may*
be followed by a comma.
For VRML >= 2.0 this all doesn't matter, comma is just a whitespace
and Lexer will never return such token. }
Lexer.NextToken;
end else
begin
{ one single field - not enclosed in [] brackets }
SingleItem.ParseValue(Lexer, Reader);
RawItemsAdd(SingleItem);
end;
finally FreeAndNil(SingleItem) end;
end;
procedure TX3DSimpleMultField.ParseXMLAttributeLexer(Lexer: TX3DLexer; Reader: TX3DReader);
var
SingleItem: TX3DSingleField;
begin
{ This is much easier and simpler in XML encoding than it was
in classic encoding. We don't have to check for [ and ] tokens,
comma is ignored (it was only for VRML 1.0 anyway), we just read
single values up to the end of stream. }
Clear;
SingleItem := CreateItemBeforeParse;
try
{ List size may be increased rapidly during parsing.
Prepare for it by allocating some size in advance. }
if RawItems is TFPSList then
TFPSList(RawItems).Capacity := 64;
while Lexer.Token <> vtEnd do
begin
SingleItem.ParseValue(Lexer, Reader);
RawItemsAdd(SingleItem);
end;
finally FreeAndNil(SingleItem) end;
end;
procedure TX3DSimpleMultField.SaveToStreamValue(Writer: TX3DWriter);
var
i: integer;
WriteIndentNextTime: boolean;
IndentMultiValueFields: boolean;
begin
case Writer.Encoding of
xeClassic:
{ The general "for I := ..." code below can handle correctly any RawItems.Count
value. But for aesthetics, i.e. more clear output for humans,
I handle the RawItems.Count = 0 and 1 cases separately. }
case Count of
0: Writer.Write('[]');
1: Writer.Write(RawItemToString(0, Writer.Encoding));
else
begin
Writer.Writeln('[');
Writer.IncIndent;
{ For really long fields, writing indentation before each item
can cost a significant disk space. So do not indent when
there are many items. }
IndentMultiValueFields := Count <= 10;
WriteIndentNextTime := IndentMultiValueFields;
for i := 0 to Count-1 do
begin
if WriteIndentNextTime then Writer.WriteIndent('');
Writer.Write(RawItemToString(i, Writer.Encoding) +',');
{ After the last item we always write newline,
no matter what's SaveToStreamDoNewLineAfterRawItem }
if (i = Count - 1) or
SaveToStreamDoNewLineAfterRawItem(i) then
begin Writer.Writeln; WriteIndentNextTime := IndentMultiValueFields end else
begin Writer.Write(' '); WriteIndentNextTime := false; end;
end;
Writer.DecIndent;
Writer.WriteIndent(']');
end;
end;
xeXML:
for I := 0 to Count - 1 do
begin
Writer.Write(RawItemToString(I, Writer.Encoding));
if I <> Count - 1 then
Writer.Write(' ');
end;
else raise EInternalError.Create('TX3DSimpleMultField.SaveToStreamValue Encoding?');
end;
end;
function TX3DSimpleMultField.SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean;
begin
result := true;
end;
function TX3DSimpleMultField.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TX3DSimpleMultField) and
(TX3DSimpleMultField(SecondValue).Count = Count) and
(TX3DSimpleMultField(SecondValue).ItemClass = ItemClass);
end;
procedure TX3DSimpleMultField.OnWarning_InvalidIndex(
const Index, ACount: Integer);
const
MaxInvalidIndexWarnings = 10;
begin
Inc(InvalidIndexWarnings);
if InvalidIndexWarnings < MaxInvalidIndexWarnings then
OnWarning(wtMajor, 'VRML/X3D', Format('Invalid index for VRML field %s (%s): index is %d, but we have only %d items', [NiceName, TypeName, Index, ACount])) else
if InvalidIndexWarnings = MaxInvalidIndexWarnings then
OnWarning(wtMajor, 'VRML/X3D', Format('Invalid index for VRML field %s (%s) reported for the %dth time. Further warnings regarding this field will not be reported (to avoid wasting time on printing countless warnings...)',
[NiceName, TypeName, InvalidIndexWarnings]));
end;
{ simple helpful parsing functions ---------------------------------------- }
{ This returns Float, not just Single, because it's used by
TSFDouble and ParseVector(double version),
that want double-precision preserved. }
function ParseFloat(Lexer: TX3DLexer): Float;
begin
Lexer.CheckTokenIs(TokenNumbers, 'float number');
result := Lexer.TokenFloat;
Lexer.NextToken;
end;
procedure ParseVector(var Vector: array of Single; Lexer: TX3DLexer); overload;
var
i: integer;
begin
for i := 0 to High(Vector) do Vector[i] := ParseFloat(Lexer);
end;
procedure ParseVector(var Vector: array of Double; Lexer: TX3DLexer); overload;
var
i: integer;
begin
for i := 0 to High(Vector) do Vector[i] := ParseFloat(Lexer);
end;
function ParseLongWord(Lexer: TX3DLexer): LongWord;
begin
Lexer.CheckTokenIs(vtInteger);
result := Lexer.TokenInteger;
Lexer.NextToken;
end;
{ TSFBool -------------------------------------------------------------------- }
constructor TSFBool.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: boolean);
begin
inherited Create(AParentNode, AName);
Value := AValue;
AssignDefaultValueFromValue;
end;
procedure TSFBool.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
procedure VRML2BooleanIntegerWarning;
begin
if Lexer.Version.Major >= 2 then
OnWarning(wtMajor, 'VRML/X3D', 'In VRML >= 2.0 you cannot express boolean values ' +
'as 0 (instead of FALSE) or 1 (instead of TRUE)');
end;
const
SBoolExpected = 'boolean constant (TRUE, FALSE)';
begin
Lexer.CheckTokenIs([vtKeyword, vtInteger], SBoolExpected);
if Lexer.Token = vtKeyword then
begin
if Lexer.TokenKeyword = vkTrue then Value := true else
if Lexer.TokenKeyword = vkFalse then Value := false else
raise EX3DParserError.Create(Lexer,
'Expected '+SBoolExpected+', got '+Lexer.DescribeToken);
end else
begin
if Lexer.TokenInteger = 1 then
begin
Value := true;
VRML2BooleanIntegerWarning;
end else
if Lexer.TokenInteger = 0 then
begin
Value := false;
VRML2BooleanIntegerWarning;
end else
raise EX3DParserError.Create(Lexer,
'Expected '+SBoolExpected+', got '+Lexer.DescribeToken);
end;
Lexer.NextToken;
end;
const
BoolKeywords: array [TX3DEncoding, boolean] of string =
( ('FALSE', 'TRUE'), ('false', 'true') );
procedure TSFBool.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(BoolKeywords[Writer.Encoding, Value]);
end;
function TSFBool.EqualsDefaultValue: boolean;
begin
result := DefaultValueExists and (DefaultValue = Value);
end;
function TSFBool.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFBool) and
(TSFBool(SecondValue).Value = Value);
end;
function TSFBool.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFBool) and
(TSFBool(SecondValue).Value = Value);
end;
procedure TSFBool.Assign(Source: TPersistent);
begin
if Source is TSFBool then
begin
DefaultValue := TSFBool(Source).DefaultValue;
DefaultValueExists := TSFBool(Source).DefaultValueExists;
Value := TSFBool(Source).Value;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFBool.AssignValue(Source: TX3DField);
begin
if Source is TSFBool then
begin
inherited;
Value := TSFBool(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFBool.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFBool.TypeName: string;
begin
Result := 'SFBool';
end;
procedure TSFBool.Send(const AValue: Boolean);
var
FieldValue: TX3DField;
begin
FieldValue := TSFBool.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFBool.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFBoolEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFFloat ------------------------------------------------------------------- }
procedure TSFFloat.SetValue(const AValue: Single);
begin
if MustBeNonnegative then
FValue := Abs(AValue) else
FValue := AValue;
end;
constructor TSFFloat.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Single);
begin
Create(AParentNode, AName, AValue, false);
end;
constructor TSFFloat.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Single; AMustBeNonnegative: boolean);
begin
inherited Create(AParentNode, AName);
FMustBeNonnegative := AMustBeNonnegative;
Value := AValue; { Set property, zeby SetValue moglo ew. zmienic Value }
AssignDefaultValueFromValue;
end;
procedure TSFFloat.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
Value := ParseFloat(Lexer);
if Angle then
FValue *= Reader.AngleConversionFactor;
end;
procedure TSFFloat.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(FloatToRawStr(Value));
end;
function TSFFloat.EqualsDefaultValue: boolean;
begin
result := DefaultValueExists and (DefaultValue = Value)
end;
function TSFFloat.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFFloat) and
(TSFFloat(SecondValue).MustBeNonnegative = MustBeNonnegative) and
FloatsEqual(TSFFloat(SecondValue).Value, Value, EqualityEpsilon);
end;
function TSFFloat.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFFloat) and
(TSFFloat(SecondValue).Value = Value);
end;
procedure TSFFloat.AssignLerp(const A: Double; Value1, Value2: TX3DField);
begin
Value := Lerp(A, (Value1 as TSFFloat).Value, (Value2 as TSFFloat).Value);
end;
function TSFFloat.CanAssignLerp: boolean;
begin
Result := true;
end;
procedure TSFFloat.Assign(Source: TPersistent);
begin
if Source is TSFFloat then
begin
DefaultValue := TSFFloat(Source).DefaultValue;
DefaultValueExists := TSFFloat(Source).DefaultValueExists;
FValue := TSFFloat(Source).Value;
FMustBeNonnegative := TSFFloat(Source).MustBeNonnegative;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFFloat.AssignValue(Source: TX3DField);
begin
if Source is TSFFloat then
begin
inherited;
Value := TSFFloat(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFFloat.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFFloat.TypeName: string;
begin
Result := 'SFFloat';
end;
procedure TSFFloat.Send(const AValue: Single);
var
FieldValue: TX3DField;
begin
FieldValue := TSFFloat.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFFloat.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFFloatEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFDouble -------------------------------------------------------------------- }
constructor TSFDouble.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Double);
begin
inherited Create(AParentNode, AName);
Value := AValue;
AssignDefaultValueFromValue;
end;
procedure TSFDouble.SetValue(const AValue: Double);
begin
FValue := AValue;
end;
procedure TSFDouble.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
Value := ParseFloat(Lexer);
if Angle then
FValue *= Reader.AngleConversionFactor;
end;
procedure TSFDouble.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(FloatToRawStr(Value));
end;
function TSFDouble.EqualsDefaultValue: boolean;
begin
Result := DefaultValueExists and (DefaultValue = Value);
end;
function TSFDouble.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFDouble) and
FloatsEqual(TSFDouble(SecondValue).Value, Value, EqualityEpsilon);
end;
function TSFDouble.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFDouble) and
(TSFDouble(SecondValue).Value = Value);
end;
procedure TSFDouble.AssignLerp(const A: Double; Value1, Value2: TX3DField);
begin
Value := Lerp(A, (Value1 as TSFDouble).Value, (Value2 as TSFDouble).Value);
end;
function TSFDouble.CanAssignLerp: boolean;
begin
Result := true;
end;
procedure TSFDouble.Assign(Source: TPersistent);
begin
if Source is TSFDouble then
begin
DefaultValue := TSFDouble(Source).DefaultValue;
DefaultValueExists := TSFDouble(Source).DefaultValueExists;
FValue := TSFDouble(Source).Value;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFDouble.AssignValue(Source: TX3DField);
begin
if Source is TSFDouble then
begin
inherited;
Value := TSFDouble(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFDouble.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFDouble.TypeName: string;
begin
Result := 'SFDouble';
end;
procedure TSFDouble.Send(const AValue: Double);
var
FieldValue: TX3DField;
begin
FieldValue := TSFDouble.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFDouble.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFDoubleEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFTime -------------------------------------------------------------------- }
class function TSFTime.TypeName: string;
begin
Result := 'SFTime';
end;
class function TSFTime.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFTimeEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFImage ------------------------------------------------------------------- }
constructor TSFImage.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TCastleImage);
begin
inherited Create(AParentNode, AName);
if AValue <> nil then
begin
FreeAndNil(Value);
Value := AValue;
end;
end;
constructor TSFImage.CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean);
begin
inherited;
{ Value must be initialized to non-nil. }
Value := TRGBImage.Create;
end;
destructor TSFImage.Destroy;
begin
FreeAndNil(Value);
inherited;
end;
procedure DecodeImageColor(const Pixel: LongWord; var G: Byte);
begin
G := Pixel and $FF;
end;
procedure DecodeImageColor(const Pixel: LongWord; var GA: TVector2Byte);
begin
GA[0] := (pixel shr 8) and $FF;
GA[1] := pixel and $FF;
end;
procedure DecodeImageColor(const Pixel: LongWord; var RGB: TVector3Byte);
begin
RGB[0] := (pixel shr 16) and $FF;
RGB[1] := (pixel shr 8) and $FF;
RGB[2] := pixel and $FF;
end;
procedure DecodeImageColor(const Pixel: LongWord; var RGBA: TVector4Byte);
begin
RGBA[0] := (pixel shr 24) and $FF;
RGBA[1] := (pixel shr 16) and $FF;
RGBA[2] := (pixel shr 8) and $FF;
RGBA[3] := pixel and $FF;
end;
{ We have to turn range checking off, because converting from LongInt
to LongWord below may cause range check errors. Yes, we want to
directly treat LongInt as 4 bytes here, because DecodeImageColor
works on separate bytes. See
http://castle-engine.sourceforge.net/x3d_implementation_texturing3d.php
comments about PixelTexture3D. }
{$include norqcheckbegin.inc}
procedure DecodeImageColor(const Pixel: LongInt; var G: Byte);
begin
DecodeImageColor(LongWord(Pixel), G);
end;
procedure DecodeImageColor(const Pixel: LongInt; var GA: TVector2Byte);
begin
DecodeImageColor(LongWord(Pixel), GA);
end;
procedure DecodeImageColor(const Pixel: LongInt; var RGB: TVector3Byte);
begin
DecodeImageColor(LongWord(Pixel), RGB);
end;
procedure DecodeImageColor(const Pixel: LongInt; var RGBA: TVector4Byte);
begin
DecodeImageColor(LongWord(Pixel), RGBA);
end;
{$include norqcheckend.inc}
procedure TSFImage.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
procedure ReplaceValue(NewValue: TCastleImage);
begin
FreeAndNil(Value);
Value := NewValue;
end;
var
w, h, comp: LongWord;
i: Cardinal;
RGBPixels: PArray_Vector3Byte;
RGBAlphaPixels: PArray_Vector4Byte;
GrayscalePixels: PByteArray;
GrayscaleAlphaPixels: PArray_Vector2Byte;
begin
{ Note that we should never let Value to be nil too long,
because even if this method exits with exception, Value should
always remain non-nil.
That's why I'm doing below Value.Empty instead of FreeAndNil(Value)
and I'm using ReplaceValue to set new Value.
This way if e.g. TRGBImage.Create with out of mem exception,
Value will still remain non-nil.
This is all because I just changed Images unit interface to class-like
and I want to do minimal changes to X3DFields unit to not break
anything. TODO -- this will be solved better in the future, by simply
allowing Value to be nil at any time.
}
Value.Empty;
w := ParseLongWord(Lexer);
h := ParseLongWord(Lexer);
comp := ParseLongWord(Lexer);
{ If w or h =0 then w*h = 0 so we don't have to read anything more.
We leave Value.IsEmpty in this case. }
if (w <> 0) and (h <> 0) then
begin
case comp of
1:begin
ReplaceValue(TGrayscaleImage.Create(w, h));
GrayscalePixels := PByteArray(Value.RawPixels);
for i := 0 to w*h-1 do
DecodeImageColor(ParseLongWord(Lexer), GrayscalePixels^[I]);
end;
2:begin
ReplaceValue(TGrayscaleAlphaImage.Create(w, h));
GrayscaleAlphaPixels := PArray_Vector2Byte(Value.RawPixels);
for i := 0 to w*h-1 do
DecodeImageColor(ParseLongWord(Lexer), GrayscaleAlphaPixels^[i]);
end;
3:begin
ReplaceValue(TRGBImage.Create(w, h));
RGBPixels := PArray_Vector3Byte(Value.RawPixels);
for i := 0 to w*h-1 do
DecodeImageColor(ParseLongWord(Lexer), RGBPixels^[i]);
end;
4:begin
ReplaceValue(TRGBAlphaImage.Create(w, h));
RGBAlphaPixels := PArray_Vector4Byte(Value.RawPixels);
for i := 0 to w*h-1 do
DecodeImageColor(ParseLongWord(Lexer), RGBAlphaPixels^[i]);
end;
else raise EX3DParserError.Create(Lexer, Format('Invalid components count'+
' for SFImage : is %d, should be 1, 2, 3 or 4.',[comp]));
end;
end;
end;
procedure TSFImage.SaveToStreamValue(Writer: TX3DWriter);
var
ga: TVector2Byte;
rgb: TVector3Byte;
rgba: TVector4Byte;
i: Cardinal;
pixel: LongWord;
begin
if Value.IsEmpty then
Writer.Write('0 0 1') else
begin
Writer.Writeln(Format('%d %d %d', [Value.Width, Value.Height,
Value.ColorComponentsCount]));
Writer.IncIndent;
Writer.WriteIndent('');
{$I NoRQCheckBegin.inc}
if Value is TGrayscaleImage then
begin
for i := 0 to Value.Width*Value.Height-1 do
begin
pixel := TGrayscaleImage(Value).GrayscalePixels[i];
Writer.Write(Format('0x%.2x ', [pixel]));
end;
end else
if Value is TGrayscaleAlphaImage then
begin
for i := 0 to Value.Width*Value.Height-1 do
begin
ga := TGrayscaleAlphaImage(Value).GrayscaleAlphaPixels[i];
pixel := (ga[0] shl 8) or ga[1];
Writer.Write(Format('0x%.4x ', [pixel]));
end;
end else
if Value is TRGBImage then
begin
for i := 0 to Value.Width*Value.Height-1 do
begin
rgb := TRGBImage(Value).RGBPixels[i];
pixel := (rgb[0] shl 16) or (rgb[1] shl 8) or rgb[2];
Writer.Write(Format('0x%.6x ', [pixel]));
end;
end else
if Value is TRGBAlphaImage then
begin
for i := 0 to Value.Width*Value.Height-1 do
begin
rgba := TRGBAlphaImage(Value).AlphaPixels[i];
pixel := (rgba[0] shl 24) or (rgba[1] shl 16) or (rgba[2] shl 8) or rgba[3];
Writer.Write(Format('0x%.8x ', [pixel]));
end;
end else
raise Exception.Create('TSFImage.SaveToStreamValue - not implemented TCastleImage descendant');
{$I NoRQCheckEnd.inc}
Writer.DecIndent;
end;
end;
function TSFImage.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFImage) and
{ TODO: compare values
(TSFImage(SecondValue).Value = Value) }true;
end;
procedure TSFImage.Assign(Source: TPersistent);
begin
if Source is TSFImage then
begin
FreeAndNil(Value);
Value := TSFImage(Source).Value.MakeCopy;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFImage.AssignValue(Source: TX3DField);
begin
if Source is TSFImage then
begin
inherited;
FreeAndNil(Value);
Value := TSFImage(Source).Value.MakeCopy;
end else
AssignValueRaiseInvalidClass(Source);
end;
class function TSFImage.TypeName: string;
begin
Result := 'SFImage';
end;
class function TSFImage.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFImageEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFLong -------------------------------------------------------------------- }
procedure TSFLong.SetValue(const AValue: Longint);
begin
if MustBeNonnegative then
FValue := Abs(AValue) else
FValue := AValue;
end;
constructor TSFLong.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Longint);
begin
Create(AParentNode, AName, AValue, false);
end;
constructor TSFLong.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: Longint; AMustBeNonnegative: boolean);
begin
inherited Create(AParentNode, AName);
FMustBeNonnegative := AMustBeNonnegative;
Value := AValue; { Set using property, zeby SetValue moglo ew. zmienic Value }
AssignDefaultValueFromValue;
end;
procedure TSFLong.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
Lexer.CheckTokenIs(vtInteger);
{ Check is TokenInteger outside of 32-bit range. }
if (Lexer.TokenInteger >= Low(LongInt)) and
(Lexer.TokenInteger <= High(LongInt)) then
begin
Value := Lexer.TokenInteger;
end else
begin
OnWarning(wtMajor, 'VRML/X3D', Format('Integer in the file is out of 32-bit range: %d',
[Lexer.TokenInteger]));
Value := -1;
end;
Lexer.NextToken;
end;
procedure TSFLong.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(IntToStr(Value));
end;
function TSFLong.EqualsDefaultValue: boolean;
begin
result := DefaultValueExists and (DefaultValue = Value)
end;
function TSFLong.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
{ Note that this means that SFInt32 and SFLong will actually be considered
equal. That's Ok, we want this. }
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFLong) and
(TSFLong(SecondValue).MustBeNonnegative = MustBeNonnegative) and
(TSFLong(SecondValue).Value = Value);
end;
function TSFLong.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFLong) and
(TSFLong(SecondValue).Value = Value);
end;
procedure TSFLong.Assign(Source: TPersistent);
begin
if Source is TSFLong then
begin
DefaultValue := TSFLong(Source).DefaultValue;
DefaultValueExists := TSFLong(Source).DefaultValueExists;
FValue := TSFLong(Source).Value;
FMustBeNonnegative := TSFLong(Source).MustBeNonnegative;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFLong.AssignValue(Source: TX3DField);
begin
if Source is TSFLong then
begin
inherited;
Value := TSFLong(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFLong.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFLong.TypeName: string;
begin
Result := 'SFLong';
end;
procedure TSFLong.Send(const AValue: LongInt);
var
FieldValue: TX3DField;
begin
FieldValue := TSFLong.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFLong.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFLongEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFInt32 ------------------------------------------------------------------- }
class function TSFInt32.TypeName: string;
begin
Result := 'SFInt32';
end;
procedure TSFInt32.Send(const AValue: LongInt);
var
FieldValue: TX3DField;
begin
FieldValue := TSFInt32.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFInt32.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFInt32Event.Create(AParentNode, AName, AInEvent);
end;
{ ----------------------------------------------------------------------------
Common SF fields based on matrices implementation }
{$define IMPLEMENT_SF_CLASS_USING_MATRICES :=
constructor TSF_CLASS.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TSF_STATIC_ITEM);
begin
inherited Create(AParentNode, AName);
FValue := AValue;
AssignDefaultValueFromValue;
end;
procedure TSF_CLASS.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
var
Column: integer;
begin
for Column := 0 to TSF_MATRIX_COLS - 1 do
ParseVector(FValue[Column], Lexer);
end;
procedure TSF_CLASS.SaveToStreamValue(Writer: TX3DWriter);
var
Column: integer;
begin
Writer.Writeln(VectorToRawStr(FValue[0]));
Writer.IncIndent;
for Column := 1 to TSF_MATRIX_COLS - 1 do
Writer.WritelnIndent(VectorToRawStr(FValue[Column]));
Writer.DecIndent;
end;
function TSF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSF_CLASS) and
MatricesEqual(TSF_CLASS(SecondValue).FValue, FValue, EqualityEpsilon);
end;
function TSF_CLASS.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSF_CLASS) and
MatricesPerfectlyEqual(TSF_CLASS(SecondValue).Value, Value);
end;
procedure TSF_CLASS.AssignLerp(const A: Double; Value1, Value2: TX3DField);
var
Column: integer;
M1, M2: PSF_STATIC_ITEM;
begin
M1 := @((Value1 as TSF_CLASS).FValue);
M2 := @((Value2 as TSF_CLASS).FValue);
for Column := 0 to TSF_MATRIX_COLS - 1 do
FValue[Column] := Lerp(A, M1^[Column], M2^[Column]);
end;
function TSF_CLASS.CanAssignLerp: boolean;
begin
Result := true;
end;
procedure TSF_CLASS.Assign(Source: TPersistent);
begin
if Source is TSF_CLASS then
begin
FValue := TSF_CLASS(Source).FValue;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSF_CLASS.AssignValue(Source: TX3DField);
begin
if Source is TSF_CLASS then
begin
inherited;
FValue := TSF_CLASS(Source).FValue;
end else
AssignValueRaiseInvalidClass(Source);
end;
function TSF_CLASS.EqualsDefaultValue: boolean;
begin
Result := DefaultValueExists and
MatricesPerfectlyEqual(DefaultValue, Value);
end;
procedure TSF_CLASS.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
procedure TSF_CLASS.Send(const AValue: TSF_STATIC_ITEM);
var
FieldValue: TX3DField;
begin
FieldValue := TSF_CLASS.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSF_CLASS.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSF_EVENT.Create(AParentNode, AName, AInEvent);
end;
}
{$define TSF_CLASS := TSFMatrix3f}
{$define TSF_STATIC_ITEM := TMatrix3Single}
{$define PSF_STATIC_ITEM := PMatrix3Single}
{$define TSF_MATRIX_COLS := 3}
{$define TSF_SCALAR := Single}
{$define TSF_EVENT := TSFMatrix3fEvent}
IMPLEMENT_SF_CLASS_USING_MATRICES
{$define TSF_CLASS := TSFMatrix3d}
{$define TSF_STATIC_ITEM := TMatrix3Double}
{$define PSF_STATIC_ITEM := PMatrix3Double}
{$define TSF_MATRIX_COLS := 3}
{$define TSF_SCALAR := Double}
{$define TSF_EVENT := TSFMatrix3dEvent}
IMPLEMENT_SF_CLASS_USING_MATRICES
{$define TSF_CLASS := TSFMatrix4f}
{$define TSF_STATIC_ITEM := TMatrix4Single}
{$define PSF_STATIC_ITEM := PMatrix4Single}
{$define TSF_MATRIX_COLS := 4}
{$define TSF_SCALAR := Single}
{$define TSF_EVENT := TSFMatrix4fEvent}
IMPLEMENT_SF_CLASS_USING_MATRICES
{$define TSF_CLASS := TSFMatrix4d}
{$define TSF_STATIC_ITEM := TMatrix4Double}
{$define PSF_STATIC_ITEM := PMatrix4Double}
{$define TSF_MATRIX_COLS := 4}
{$define TSF_SCALAR := Double}
{$define TSF_EVENT := TSFMatrix4dEvent}
IMPLEMENT_SF_CLASS_USING_MATRICES
{ TSFMatrix3f ------------------------------------------------------------------ }
class function TSFMatrix3f.TypeName: string;
begin
Result := 'SFMatrix3f';
end;
{ TSFMatrix3d ------------------------------------------------------------------ }
class function TSFMatrix3d.TypeName: string;
begin
Result := 'SFMatrix3d';
end;
{ TSFMatrix4f ------------------------------------------------------------------ }
class function TSFMatrix4f.TypeName: string;
begin
Result := 'SFMatrix4f';
end;
function TSFMatrix4f.TransformScale: Single;
begin
{ This is a simple method of extracting average scaling factor from
a matrix. Works OK for combination of identity, scaling,
translation matrices.
Fails awfully on rotation (and possibly many other) matrices. }
Result := ( FValue[0, 0] +
FValue[1, 1] +
FValue[2, 2] ) / 3;
end;
{ TSFMatrix4d ------------------------------------------------------------------ }
class function TSFMatrix4d.TypeName: string;
begin
Result := 'SFMatrix4d';
end;
{ TSFMatrix ------------------------------------------------------------------ }
class function TSFMatrix.TypeName: string;
begin
Result := 'SFMatrix';
end;
procedure TSFMatrix.Send(const AValue: TMatrix4Single);
var
FieldValue: TX3DField;
begin
FieldValue := TSFMatrix.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
{ TSFRotation ---------------------------------------------------------------- }
constructor TSFRotation.Create(AParentNode: TX3DFileItem;
const AName: string;
const AnAxis: TVector3Single; const ARotationRad: Single);
begin
inherited Create(AParentNode, AName);
Axis := AnAxis;
RotationRad := ARotationRad;
AssignDefaultValueFromValue;
end;
constructor TSFRotation.Create(AParentNode: TX3DFileItem;
const AName: string;
const AValue: TVector4Single);
var
AnAxis: TVector3Single absolute AValue;
begin
inherited Create(AParentNode, AName);
Axis := AnAxis;
RotationRad := AValue[3];
AssignDefaultValueFromValue;
end;
procedure TSFRotation.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
ParseVector(Axis, Lexer);
RotationRad := ParseFloat(Lexer) * Reader.AngleConversionFactor;
end;
function TSFRotation.GetValue: TVector4Single;
begin
Move(Axis[0], Result[0], SizeOf(Single) * 3);
Result[3] := RotationRad;
end;
procedure TSFRotation.SetValue(const AValue: TVector4Single);
begin
Axis[0] := AValue[0];
Axis[1] := AValue[1];
Axis[2] := AValue[2];
RotationRad := AValue[3];
end;
function TSFRotation.GetValueDeg: TVector4Single;
begin
Move(Axis[0], Result[0], SizeOf(Single) * 3);
Result[3] := RadToDeg(RotationRad);
end;
procedure TSFRotation.SetValueDeg(const AValue: TVector4Single);
begin
Axis[0] := AValue[0];
Axis[1] := AValue[1];
Axis[2] := AValue[2];
RotationRad := DegToRad(AValue[3]);
end;
procedure TSFRotation.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(VectorToRawStr(Axis) +' ' +FloatToRawStr(RotationRad));
end;
function TSFRotation.RotatedPoint(const pt: TVector3Single): TVector3Single;
begin
if not ZeroVector(Axis) then
Result := RotatePointAroundAxisRad(RotationRad, pt, Axis) else
begin
{ Safeguard against rotation around zero vector, which produces unpredictable
results (actually, Result would be filled with Nan values).
VRML spec says that SFRotation should always specify a normalized vector. }
Result := Pt;
OnWarning(wtMajor, 'VRML/X3D', Format('SFRotation field (%s) specifies rotation around zero vector', [NiceName]));
end;
end;
function TSFRotation.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFRotation) and
VectorsEqual(TSFRotation(SecondValue).Axis, Axis, EqualityEpsilon) and
FloatsEqual(TSFRotation(SecondValue).RotationRad, RotationRad, EqualityEpsilon);
end;
function TSFRotation.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFRotation) and
VectorsPerfectlyEqual(TSFRotation(SecondValue).Axis, Axis) and
(TSFRotation(SecondValue).RotationRad = RotationRad);
end;
function TSFRotation.EqualsDefaultValue: boolean;
begin
Result := DefaultValueExists and
VectorsPerfectlyEqual(DefaultAxis, Axis) and
(DefaultRotationRad = RotationRad);
end;
procedure TSFRotation.AssignLerp(const A: Double; Value1, Value2: TX3DField);
begin
Axis := Lerp(A, (Value1 as TSFRotation).Axis , (Value2 as TSFRotation).Axis);
RotationRad := Lerp(A, (Value1 as TSFRotation).RotationRad, (Value2 as TSFRotation).RotationRad);
end;
function TSFRotation.CanAssignLerp: boolean;
begin
Result := true;
end;
procedure TSFRotation.Assign(Source: TPersistent);
begin
if Source is TSFRotation then
begin
Axis := TSFRotation(Source).Axis;
RotationRad := TSFRotation(Source).RotationRad;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFRotation.AssignValue(Source: TX3DField);
begin
if Source is TSFRotation then
begin
inherited;
Axis := TSFRotation(Source).Axis;
RotationRad := TSFRotation(Source).RotationRad;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFRotation.AssignDefaultValueFromValue;
begin
inherited;
DefaultAxis := Axis;
DefaultRotationRad := RotationRad;
DefaultValueExists := true;
end;
class function TSFRotation.TypeName: string;
begin
Result := 'SFRotation';
end;
procedure TSFRotation.Send(const AValue: Tvector4Single);
var
FieldValue: TX3DField;
begin
FieldValue := TSFRotation.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFRotation.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFRotationEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFString ------------------------------------------------------------------ }
constructor TSFString.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: string);
begin
inherited Create(AParentNode, AName);
Value := AValue;
AssignDefaultValueFromValue;
end;
procedure TSFString.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
Lexer.CheckTokenIs(vtString);
Value := Lexer.TokenString;
Lexer.NextToken;
end;
procedure TSFString.SaveToStreamValue(Writer: TX3DWriter);
begin
case Writer.Encoding of
xeClassic: Writer.Write(StringToX3DClassic(Value));
xeXML : Writer.Write(StringToX3DXml(Value));
else raise EInternalError.Create('TSFString.SaveToStreamValue Encoding?');
end;
end;
function TSFString.EqualsDefaultValue: boolean;
begin
Result := DefaultValueExists and (DefaultValue = Value);
end;
function TSFString.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFString) and
(TSFString(SecondValue).Value = Value);
end;
function TSFString.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSFString) and
(TSFString(SecondValue).Value = Value);
end;
procedure TSFString.Assign(Source: TPersistent);
begin
if Source is TSFString then
begin
DefaultValue := TSFString(Source).DefaultValue;
DefaultValueExists := TSFString(Source).DefaultValueExists;
Value := TSFString(Source).Value;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFString.AssignValue(Source: TX3DField);
begin
if Source is TSFString then
begin
inherited;
Value := TSFString(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFString.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFString.TypeName: string;
begin
Result := 'SFString';
end;
procedure TSFString.ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader);
begin
{ SFString has quite special interpretation, it's just attrib
name. It would not be usefull trying to use TX3DLexer here,
it's easier just to handle this as a special case.
Uhm... some X3D XML files commit the reverse mistake
as for MFString: they *include* additional quotes around the string.
Spec says that for SFString, such quotes are not needed.
Example: openlibraries trunk/media files.
I detect this, warn and strip quotes. }
if (Length(AttributeValue) >= 2) and
(AttributeValue[1] = '"') and
(AttributeValue[Length(AttributeValue)] = '"') then
begin
OnWarning(wtMajor, 'VRML/X3D', 'X3D XML: found extra quotes around SFString value. Assuming this is a mistake, and stripping quotes from ''' + AttributeValue + '''. Fix your model: SFString field values should not be enclosed in extra quotes!');
Value := Copy(AttributeValue, 2, Length(AttributeValue) - 2);
end else
Value := AttributeValue;
end;
procedure TSFString.Send(const AValue: AnsiString);
var
FieldValue: TX3DField;
begin
FieldValue := TSFString.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
function TSFString.SaveToXmlValue: TSaveToXmlMethod;
begin
Result := sxAttributeCustomQuotes;
end;
class function TSFString.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFStringEvent.Create(AParentNode, AName, AInEvent);
end;
{ ----------------------------------------------------------------------------
Common SF fields based on vectors implementation }
{$define IMPLEMENT_SF_CLASS_USING_VECTORS :=
constructor TSF_CLASS.Create(AParentNode: TX3DFileItem;
const AName: string; const AValue: TSF_STATIC_ITEM);
begin
inherited Create(AParentNode, AName);
Value := AValue;
AssignDefaultValueFromValue;
end;
procedure TSF_CLASS.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
begin
ParseVector(Value, Lexer);
end;
procedure TSF_CLASS.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(VectorToRawStr(Value));
end;
function TSF_CLASS.EqualsDefaultValue: boolean;
begin
result := DefaultValueExists and VectorsPerfectlyEqual(DefaultValue, Value);
end;
function TSF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSF_CLASS) and
VectorsEqual(TSF_CLASS(SecondValue).Value, Value, EqualityEpsilon);
end;
function TSF_CLASS.FastEqualsValue(SecondValue: TX3DField): boolean;
begin
Result := (SecondValue is TSF_CLASS) and
VectorsPerfectlyEqual(TSF_CLASS(SecondValue).Value, Value);
end;
procedure TSF_CLASS.AssignLerp(const A: Double; Value1, Value2: TX3DField);
begin
Value := Lerp(A, (Value1 as TSF_CLASS).Value, (Value2 as TSF_CLASS).Value);
end;
function TSF_CLASS.CanAssignLerp: boolean;
begin
Result := true;
end;
procedure TSF_CLASS.Assign(Source: TPersistent);
begin
if Source is TSF_CLASS then
begin
DefaultValue := TSF_CLASS(Source).DefaultValue;
DefaultValueExists := TSF_CLASS(Source).DefaultValueExists;
Value := TSF_CLASS(Source).Value;
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSF_CLASS.AssignValue(Source: TX3DField);
begin
if Source is TSF_CLASS then
begin
inherited;
Value := TSF_CLASS(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSF_CLASS.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
procedure TSF_CLASS.Send(const AValue: TSF_STATIC_ITEM);
var
FieldValue: TX3DField;
begin
FieldValue := TSF_CLASS.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSF_CLASS.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSF_EVENT.Create(AParentNode, AName, AInEvent);
end;
}
{$define TSF_CLASS := TSFVec2f}
{$define TSF_SCALAR := Single}
{$define TSF_STATIC_ITEM := TVector2Single}
{$define TSF_EVENT := TSFVec2fEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{$define TSF_CLASS := TSFVec3f}
{$define TSF_SCALAR := Single}
{$define TSF_STATIC_ITEM := TVector3Single}
{$define TSF_EVENT := TSFVec3fEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{$define TSF_CLASS := TSFVec4f}
{$define TSF_SCALAR := Single}
{$define TSF_STATIC_ITEM := TVector4Single}
{$define TSF_EVENT := TSFVec4fEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{$define TSF_CLASS := TSFVec2d}
{$define TSF_SCALAR := Double}
{$define TSF_STATIC_ITEM := TVector2Double}
{$define TSF_EVENT := TSFVec2dEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{$define TSF_CLASS := TSFVec3d}
{$define TSF_SCALAR := Double}
{$define TSF_STATIC_ITEM := TVector3Double}
{$define TSF_EVENT := TSFVec3dEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{$define TSF_CLASS := TSFVec4d}
{$define TSF_SCALAR := Double}
{$define TSF_STATIC_ITEM := TVector4Double}
{$define TSF_EVENT := TSFVec4dEvent}
IMPLEMENT_SF_CLASS_USING_VECTORS
{ TSFVec2f ------------------------------------------------------------------- }
class function TSFVec2f.TypeName: string;
begin
Result := 'SFVec2f';
end;
{ TSFVec3f ------------------------------------------------------------------- }
class function TSFVec3f.TypeName: string;
begin
Result := 'SFVec3f';
end;
procedure TSFVec3f.Send(const Index: Integer; const ComponentValue: Single);
var
V: TVector3Single;
begin
V := Value;
V[Index] := ComponentValue;
Send(V);
end;
{ TSFColor ------------------------------------------------------------------- }
class function TSFColor.TypeName: string;
begin
Result := 'SFColor';
end;
procedure TSFColor.Send(const AValue: TVector3Single);
var
FieldValue: TX3DField;
begin
FieldValue := TSFColor.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFColor.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFColorEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFVec4f ------------------------------------------------------------------- }
class function TSFVec4f.TypeName: string;
begin
Result := 'SFVec4f';
end;
{ TSFColorRGBA --------------------------------------------------------------- }
class function TSFColorRGBA.TypeName: string;
begin
Result := 'SFColorRGBA';
end;
procedure TSFColorRGBA.Send(const AValue: TVector4Single);
var
FieldValue: TX3DField;
begin
FieldValue := TSFColorRGBA.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TSFColorRGBA.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TSFColorRGBAEvent.Create(AParentNode, AName, AInEvent);
end;
{ TSFVec2d ------------------------------------------------------------------- }
class function TSFVec2d.TypeName: string;
begin
Result := 'SFVec2d';
end;
{ TSFVec3d ------------------------------------------------------------------- }
class function TSFVec3d.TypeName: string;
begin
Result := 'SFVec3d';
end;
{ TSFVec4d ------------------------------------------------------------------- }
class function TSFVec4d.TypeName: string;
begin
Result := 'SFVec4d';
end;
{ TSFBitMask ------------------------------------------------------------ }
constructor TSFBitMask.Create(AParentNode: TX3DFileItem;
const AName: string; const AFlagNames: array of string;
const ANoneString, AAllString: string; const AFlags: array of boolean);
var
i: integer;
begin
inherited Create(AParentNode, AName);
fFlagNames := TStringListCaseSens.Create;
AddStrArrayToStrings(AFlagNames, fFlagNames);
for i := 0 to FlagsCount-1 do Flags[i] := AFlags[i];
fNoneString := ANoneString;
fAllString := AAllString;
Assert(NoneString <> '', 'NoneString must be defined for SFBitMask');
end;
destructor TSFBitMask.Destroy;
begin
fFlagNames.Free;
inherited;
end;
function TSFBitMask.GetFlags(i: integer): boolean;
begin
result := i in fFlags
end;
procedure TSFBitMask.SetFlags(i: integer; value: boolean);
begin
if value then Include(fFlags, i) else Exclude(fFlags, i)
end;
function TSFBitMask.FlagsCount: integer;
begin
result := fFlagNames.Count
end;
function TSFBitMask.GetFlagNames(i: integer): string;
begin
result := fFlagNames[i]
end;
procedure TSFBitMask.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
procedure InterpretTokenAsFlagName;
var
i: integer;
begin
Lexer.CheckTokenIs(vtName, 'bit mask constant');
i := fFlagNames.IndexOf(Lexer.TokenName);
if i >= 0 then
Flags[i] := true else
if Lexer.TokenName = fAllString then
fFlags := [0..FlagsCount-1] else
if Lexer.TokenName = fNoneString then
{ Don't set anything. Note that this doesn't clear other flags,
so e.g. "( FLAG_1 | NONE )" equals just "FLAG_1". } else
raise EX3DParserError.Create(Lexer,
'Expected bit mask constant, got '+Lexer.DescribeToken);
end;
begin
fFlags:=[];
if Lexer.Token = vtOpenBracket then
begin
repeat
Lexer.NextToken;
InterpretTokenAsFlagName;
Lexer.NextToken;
until Lexer.Token <> vtBar;
Lexer.CheckTokenIs(vtCloseBracket);
Lexer.NextToken;
end else
begin
InterpretTokenAsFlagName;
Lexer.NextToken;
end;
end;
function TSFBitMask.AreAllFlags(value: boolean): boolean;
var
i: integer;
begin
for i := 0 to FlagsCount-1 do
if Flags[i] <> value then exit(false);
exit(true);
end;
procedure TSFBitMask.SaveToStreamValue(Writer: TX3DWriter);
var
i: integer;
PrecedeWithBar: boolean;
begin
{ This is an VRML 1.0 (and Inventor) type. The existing specs only say
how to encode it for classic encoding. For XML, we just use the same format. }
if AreAllFlags(false) then
Writer.Write(NoneString) else
begin
{ We don't really need AllString to express that all bit are set
(we could as well just name them all), but it looks nicer. }
if (AllString <> '') and AreAllFlags(true) then
Writer.Write(AllString) else
begin
PrecedeWithBar := false;
Writer.Write('(');
for i := 0 to FlagsCount-1 do
if Flags[i] then
begin
if PrecedeWithBar then Writer.Write('|') else PrecedeWithBar := true;
Writer.Write(FlagNames[i]);
end;
Writer.Write(')');
end;
end;
end;
function TSFBitMask.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFBitMask) and
(TSFBitMask(SecondValue).FFlagNames.Equals(FFlagNames)) and
(TSFBitMask(SecondValue).FFlags = FFlags) and
(TSFBitMask(SecondValue).AllString = AllString) and
(TSFBitMask(SecondValue).NoneString = NoneString);
end;
procedure TSFBitMask.Assign(Source: TPersistent);
begin
if Source is TSFBitMask then
begin
FAllString := TSFBitMask(Source).AllString;
FNoneString := TSFBitMask(Source).NoneString;
FFlags := TSFBitMask(Source).FFlags;
FFlagNames.Assign(TSFBitMask(Source).FFlagNames);
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFBitMask.AssignValue(Source: TX3DField);
begin
if Source is TSFBitMask then
begin
inherited;
FFlags := TSFBitMask(Source).FFlags;
end else
AssignValueRaiseInvalidClass(Source);
end;
class function TSFBitMask.TypeName: string;
begin
Result := 'SFBitMask';
end;
{ TSFEnum ----------------------------------------------------------------- }
constructor TSFEnum.Create(AParentNode: TX3DFileItem;
const AName: string; const AEnumNames: array of string; const AValue: integer);
begin
inherited Create(AParentNode, AName);
fEnumNames := TStringListCaseSens.Create;
AddStrArrayToStrings(AEnumNames, fEnumNames);
Value := AValue;
AssignDefaultValueFromValue;
end;
destructor TSFEnum.Destroy;
begin
fEnumNames.Free;
inherited;
end;
function TSFEnum.GetEnumNames(i: integer): string;
begin
result := fEnumNames[i]
end;
function TSFEnum.EnumNamesCount: integer;
begin
result := fEnumNames.Count
end;
procedure TSFEnum.ParseValue(Lexer: TX3DLexer; Reader: TX3DReader);
var
val: integer;
begin
Lexer.CheckTokenIs(vtName, 'enumerated type constant');
val := fEnumNames.IndexOf(Lexer.TokenName);
if val = -1 then
raise EX3DParserError.Create(Lexer,
'Expected enumerated type constant, got '+Lexer.DescribeToken);
Value := val;
Lexer.NextToken;
end;
procedure TSFEnum.SaveToStreamValue(Writer: TX3DWriter);
begin
Writer.Write(EnumNames[Value]);
end;
function TSFEnum.EqualsDefaultValue: boolean;
begin
result := DefaultValueExists and (DefaultValue = Value);
end;
function TSFEnum.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TSFEnum) and
(TSFEnum(SecondValue).FEnumNames.Equals(FEnumNames)) and
(TSFEnum(SecondValue).Value = Value);
end;
procedure TSFEnum.Assign(Source: TPersistent);
begin
if Source is TSFEnum then
begin
DefaultValue := TSFEnum(Source).DefaultValue;
DefaultValueExists := TSFEnum(Source).DefaultValueExists;
Value := TSFEnum(Source).Value;
FEnumNames.Assign(TSFEnum(Source).FEnumNames);
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TSFEnum.AssignValue(Source: TX3DField);
begin
if Source is TSFEnum then
begin
inherited;
Value := TSFEnum(Source).Value;
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TSFEnum.AssignDefaultValueFromValue;
begin
inherited;
DefaultValue := Value;
DefaultValueExists := true;
end;
class function TSFEnum.TypeName: string;
begin
Result := 'SFEnum';
end;
procedure TSFEnum.Send(const AValue: LongInt);
var
FieldValue: TX3DField;
begin
FieldValue := TSFEnum.Create(ParentNode, Name, [], AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
{ multiple value fields ----------------------------------------------------- }
{ Note that because of FPC 2.0.2 bug, code below will not compile
with FPC 2.0.2 in objfpc mode. For objfpc mode I would have to
change below Items.Items[I] to Items.L[I],
i.e. Items property of my dynamic array classes will not work
correctly in objfpc mode in FPC 2.0.2.
Fixed in FPC 2.0.3 and 2.1.1 (revision 2911).
}
{$ifdef FPC_OBJFPC}
{$ifdef VER2_0_2}
{$fatal This code will not compile with FPC 2.0.2 in objfpc mode}
{$endif}
{$endif}
{$define IMPLEMENT_MF_CLASS:=
constructor TMF_CLASS.Create(AParentNode: TX3DFileItem;
const AName: string;
const InitialContent: array of TMF_STATIC_ITEM);
begin
inherited Create(AParentNode, AName);
Items.AddArray(InitialContent);
AssignDefaultValueFromValue;
end;
constructor TMF_CLASS.CreateUndefined(AParentNode: TX3DFileItem;
const AName: string; const AExposed: boolean);
begin
inherited;
FItemClass := TMF_CLASS_ITEM;
RawItems := TMF_DYN_STATIC_ITEM_ARRAY.Create;
DefaultValuesCount := -1;
end;
function TMF_CLASS.GetItems: TMF_DYN_STATIC_ITEM_ARRAY;
begin
Result := TMF_DYN_STATIC_ITEM_ARRAY(RawItems)
end;
procedure TMF_CLASS.SetItems(const Value: TMF_DYN_STATIC_ITEM_ARRAY);
begin
TMF_DYN_STATIC_ITEM_ARRAY(RawItems).Assign(Value);
end;
procedure TMF_CLASS.RawItemsAdd(Item: TX3DSingleField);
begin
Items.Add(TMF_CLASS_ITEM(Item).Value);
end;
procedure TMF_CLASS.Assign(Source: TPersistent);
begin
if Source is TMF_CLASS then
begin
DefaultValuesCount := TMF_CLASS(Source).DefaultValuesCount;
DefaultValue := TMF_CLASS(Source).DefaultValue;
Items.Assign(TMF_CLASS(Source).Items);
VRMLFieldAssignCommon(TX3DField(Source));
end else
inherited;
end;
procedure TMF_CLASS.AssignValue(Source: TX3DField);
begin
if Source is TMF_CLASS then
begin
inherited;
Items.Assign(TMF_CLASS(Source).Items);
end else
AssignValueRaiseInvalidClass(Source);
end;
procedure TMF_CLASS.AssignDefaultValueFromValue;
begin
inherited;
(* initialize default value of the field: DefaultValuesCount, and (only
in case of DefaultValuesCount = 1 for now) initialize also DefaultValue *)
case Items.Count of
0: DefaultValuesCount := 0;
1: begin
DefaultValuesCount := 1;
DefaultValue := Items.L[0];
end;
else DefaultValuesCount := -1;
end;
end;
procedure TMF_CLASS.Send(const AValue: array of TMF_STATIC_ITEM);
var
FieldValue: TX3DField;
begin
FieldValue := TMF_CLASS.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
function TMF_CLASS.GetItemsSafe(Index: Integer): TMF_STATIC_ITEM;
begin
if (Index >= 0) and (Index < Items.Count) then
Result := Items.L[Index] else
begin
OnWarning_InvalidIndex(Index, Count);
Result := TMF_DYN_DEFAULT_SAFE_VALUE;
end;
end;
procedure TMF_CLASS.SetItemsSafe(Index: Integer; const Value: TMF_STATIC_ITEM);
begin
if (Index >= 0) and (Index < Items.Count) then
Items.L[Index] := Value else
begin
OnWarning_InvalidIndex(Index, Count);
end;
end;
class function TMF_CLASS.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TMF_EVENT.Create(AParentNode, AName, AInEvent);
end;
}
{ Choose one of macros IMPLEMENT_MF_CLASS_USING_* to specify
which comparison operator is suitable for given field type.
For some types operator "=" may not be available, like for vectors
(where it would be unsure what it does --- precise or epsilon comparison?).
Then using other comparison, like CompareMem, may be suitable.
}
{$define IMPLEMENT_MF_CLASS_USING_EQUALITY_OP:=
function TMF_CLASS.EqualsDefaultValue: boolean;
begin
result :=
((DefaultValuesCount = 0) and (Count = 0)) or
((DefaultValuesCount = 1) and (Count = 1) and
(DefaultValue = Items.L[0]));
end;
function TMF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
var
I: Integer;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TMF_CLASS);
if Result then
for I := 0 to Items.Count - 1 do
if not (TMF_CLASS(SecondValue).Items.L[I] = Items.L[I]) then
Exit(false);
end;
}
{$define IMPLEMENT_MF_CLASS_USING_VECTORS:=
function TMF_CLASS.EqualsDefaultValue: boolean;
begin
result :=
((DefaultValuesCount = 0) and (Count = 0)) or
((DefaultValuesCount = 1) and (Count = 1) and
VectorsPerfectlyEqual(DefaultValue, Items.L[0]) );
end;
function TMF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
var
I: Integer;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TMF_CLASS);
if Result then
for I := 0 to Items.Count - 1 do
if not VectorsEqual(TMF_CLASS(SecondValue).Items.L[I], Items.L[I],
EqualityEpsilon) then
Exit(false);
end;
function TMF_CLASS.RawItemToString(ItemNum: Integer; const Encoding: TX3DEncoding): string;
begin
Result := VectorToRawStr(Items.L[ItemNum])
end;
procedure TMF_CLASS.AssignLerp(const A: Double; Value1, Value2: TX3DField);
var
I: Integer;
Val1, Val2: TMF_CLASS;
Items1, Items2: TMF_DYN_STATIC_ITEM_ARRAY;
begin
Val1 := Value1 as TMF_CLASS;
Val2 := Value2 as TMF_CLASS;
Val1.CheckCountEqual(Val2);
Items.Count := Val1.Items.Count;
Items1 := Val1.Items;
Items2 := Val2.Items;
for I := 0 to Items.Count - 1 do
Items.L[I] := Lerp(A, Items1.L[I], Items2.L[I]);
end;
function TMF_CLASS.CanAssignLerp: boolean;
begin
Result := true;
end;
}
{$define IMPLEMENT_MF_CLASS_USING_MATRICES:=
function TMF_CLASS.EqualsDefaultValue: boolean;
begin
result :=
((DefaultValuesCount = 0) and (Count = 0)) or
((DefaultValuesCount = 1) and (Count = 1) and
MatricesPerfectlyEqual(DefaultValue, Items.L[0]) );
end;
function TMF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
var
I: Integer;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TMF_CLASS);
if Result then
for I := 0 to Items.Count - 1 do
if not MatricesEqual(TMF_CLASS(SecondValue).Items.L[I], Items.L[I],
EqualityEpsilon) then
Exit(false);
end;
function TMF_CLASS.RawItemToString(ItemNum: Integer; const Encoding: TX3DEncoding): string;
var
Column: Integer;
begin
Result := VectorToRawStr(Items.L[ItemNum][0]);
for Column := 1 to TSF_MATRIX_COLS - 1 do
Result += ' ' + VectorToRawStr(Items.L[ItemNum][Column]);
end;
procedure TMF_CLASS.AssignLerp(const A: Double; Value1, Value2: TX3DField);
var
I: Integer;
Val1, Val2: TMF_CLASS;
Items1, Items2: TMF_DYN_STATIC_ITEM_ARRAY;
begin
Val1 := Value1 as TMF_CLASS;
Val2 := Value2 as TMF_CLASS;
Val1.CheckCountEqual(Val2);
Items.Count := Val1.Items.Count;
Items1 := Val1.Items;
Items2 := Val2.Items;
for I := 0 to Items.Count - 1 do
Items.L[I] := Lerp(A, Items1.L[I], Items2.L[I]);
end;
function TMF_CLASS.CanAssignLerp: boolean;
begin
Result := true;
end;
}
{$define IMPLEMENT_MF_CLASS_USING_FLOATS_EQUAL:=
function TMF_CLASS.EqualsDefaultValue: boolean;
begin
result :=
((DefaultValuesCount = 0) and (Count = 0)) or
((DefaultValuesCount = 1) and (Count = 1) and
(DefaultValue = Items.L[0]) );
end;
function TMF_CLASS.Equals(SecondValue: TX3DField;
const EqualityEpsilon: Double): boolean;
var
I: Integer;
begin
Result := (inherited Equals(SecondValue, EqualityEpsilon)) and
(SecondValue is TMF_CLASS);
if Result then
for I := 0 to Items.Count - 1 do
if not FloatsEqual(TMF_CLASS(SecondValue).Items.L[I], Items.L[I],
EqualityEpsilon) then
Exit(false);
end;
}
{$define TMF_CLASS := TMFBool}
{$define TMF_STATIC_ITEM := boolean}
{$define TMF_CLASS_ITEM := TSFBool}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TBooleanList}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := false}
{$define TMF_EVENT := TMFBoolEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_EQUALITY_OP
{$define TMF_CLASS := TMFLong}
{$define TMF_STATIC_ITEM := Longint}
{$define TMF_CLASS_ITEM := TSFLong}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TLongintList}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := 0}
{$define TMF_EVENT := TMFLongEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_EQUALITY_OP
{$define TMF_CLASS := TMFVec2f}
{$define TMF_STATIC_ITEM := TVector2Single}
{$define TMF_CLASS_ITEM := TSFVec2f}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector2SingleList}
{$define TMF_SCALAR := Single}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := ZeroVector2Single}
{$define TMF_EVENT := TMFVec2fEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFVec3f}
{$define TMF_STATIC_ITEM := TVector3Single}
{$define TMF_CLASS_ITEM := TSFVec3f}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector3SingleList}
{$define TMF_SCALAR := Single}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := ZeroVector3Single}
{$define TMF_EVENT := TMFVec3fEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFVec4f}
{$define TMF_STATIC_ITEM := TVector4Single}
{$define TMF_CLASS_ITEM := TSFVec4f}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector4SingleList}
{$define TMF_SCALAR := Single}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := Vector4Single(0, 0, 0, 1)}
{$define TMF_EVENT := TMFVec4fEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFVec2d}
{$define TMF_STATIC_ITEM := TVector2Double}
{$define TMF_CLASS_ITEM := TSFVec2d}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector2DoubleList}
{$define TMF_SCALAR := Double}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := ZeroVector2Double}
{$define TMF_EVENT := TMFVec2dEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFVec3d}
{$define TMF_STATIC_ITEM := TVector3Double}
{$define TMF_CLASS_ITEM := TSFVec3d}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector3DoubleList}
{$define TMF_SCALAR := Double}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := ZeroVector3Double}
{$define TMF_EVENT := TMFVec3dEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFVec4d}
{$define TMF_STATIC_ITEM := TVector4Double}
{$define TMF_CLASS_ITEM := TSFVec4d}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector4DoubleList}
{$define TMF_SCALAR := Double}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := Vector4Double(0, 0, 0, 1)}
{$define TMF_EVENT := TMFVec4dEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFRotation}
{$define TMF_STATIC_ITEM := TVector4Single}
{$define TMF_CLASS_ITEM := TSFRotation}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TVector4SingleList}
{$define TMF_SCALAR := Single}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := DefaultRotation}
{$define TMF_EVENT := TMFRotationEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_VECTORS
{$define TMF_CLASS := TMFFloat}
{$define TMF_STATIC_ITEM := Single}
{$define TMF_CLASS_ITEM := TSFFloat}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TSingleList}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := 0}
{$define TMF_EVENT := TMFFloatEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_FLOATS_EQUAL
{$define TMF_CLASS := TMFDouble}
{$define TMF_STATIC_ITEM := Double}
{$define TMF_CLASS_ITEM := TSFDouble}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TDoubleList}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := 0}
{$define TMF_EVENT := TMFDoubleEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_FLOATS_EQUAL
{$define TMF_CLASS := TMFString}
{$define TMF_STATIC_ITEM := string}
{$define TMF_CLASS_ITEM := TSFString}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TCastleStringList}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := ''}
{$define TMF_EVENT := TMFStringEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_EQUALITY_OP
{$define TMF_CLASS := TMFMatrix3f}
{$define TMF_STATIC_ITEM := TMatrix3Single}
{$define TMF_CLASS_ITEM := TSFMatrix3f}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TMatrix3SingleList}
{$define TMF_SCALAR := Single}
{$define TSF_MATRIX_COLS := 3}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := IdentityMatrix3Single}
{$define TMF_EVENT := TMFMatrix3fEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_MATRICES
{$define TMF_CLASS := TMFMatrix3d}
{$define TMF_STATIC_ITEM := TMatrix3Double}
{$define TMF_CLASS_ITEM := TSFMatrix3d}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TMatrix3DoubleList}
{$define TMF_SCALAR := Double}
{$define TSF_MATRIX_COLS := 3}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := IdentityMatrix3Double}
{$define TMF_EVENT := TMFMatrix3dEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_MATRICES
{$define TMF_CLASS := TMFMatrix4f}
{$define TMF_STATIC_ITEM := TMatrix4Single}
{$define TMF_CLASS_ITEM := TSFMatrix4f}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TMatrix4SingleList}
{$define TMF_SCALAR := Single}
{$define TSF_MATRIX_COLS := 4}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := IdentityMatrix4Single}
{$define TMF_EVENT := TMFMatrix4fEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_MATRICES
{$define TMF_CLASS := TMFMatrix4d}
{$define TMF_STATIC_ITEM := TMatrix4Double}
{$define TMF_CLASS_ITEM := TSFMatrix4d}
{$define TMF_DYN_STATIC_ITEM_ARRAY := TMatrix4DoubleList}
{$define TMF_SCALAR := Double}
{$define TSF_MATRIX_COLS := 4}
{$define TMF_DYN_DEFAULT_SAFE_VALUE := IdentityMatrix4Double}
{$define TMF_EVENT := TMFMatrix4dEvent}
IMPLEMENT_MF_CLASS
IMPLEMENT_MF_CLASS_USING_MATRICES
{ TMFBool ------------------------------------------------------------------ }
function TMFBool.RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string;
begin
Result := BoolKeywords[Encoding][Items[ItemNum]];
end;
class function TMFBool.TypeName: string;
begin
Result := 'MFBool';
end;
{ TMFLong -------------------------------------------------------------------- }
function TMFLong.SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean;
begin
Result := SaveToStreamLineUptoNegative and (Items[ItemNum] < 0);
end;
function TMFLong.RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string;
begin
Result := IntToStr(Items[ItemNum])
end;
class function TMFLong.TypeName: string;
begin
Result := 'MFLong';
end;
procedure TMFLong.OnWarning_WrongVertexIndex(
const GeometryNodeTypeName: string;
const VertexNum: Integer; const CoordCount: Integer);
const
MaxWrongVertexIndexWarnings = 10;
begin
Inc(WrongVertexIndexWarnings);
if WrongVertexIndexWarnings < MaxWrongVertexIndexWarnings then
OnWarning(wtMajor, 'VRML/X3D', Format('Wrong vertex index in indexed node %s (not enouch points in Coordinate node defined: index is %d, we have only %d vertices)',
[GeometryNodeTypeName, VertexNum, CoordCount])) else
if WrongVertexIndexWarnings = MaxWrongVertexIndexWarnings then
OnWarning(wtMajor, 'VRML/X3D', Format('Wrong vertex index in indexed node %s reported for the %dth time. Further warnings regarding this field will not be reported (to avoid wasting time on printing countless warnings...)',
[GeometryNodeTypeName, WrongVertexIndexWarnings]));
end;
{ TMFInt32 ------------------------------------------------------------------- }
class function TMFInt32.TypeName: string;
begin
Result := 'MFInt32';
end;
procedure TMFInt32.Send(const AValue: array of LongInt);
var
FieldValue: TX3DField;
begin
FieldValue := TMFInt32.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TMFInt32.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TMFInt32Event.Create(AParentNode, AName, AInEvent);
end;
{ TMFMatrix3f ------------------------------------------------------------------- }
class function TMFMatrix3f.TypeName: string;
begin
Result := 'MFMatrix3f';
end;
{ TMFMatrix3d ------------------------------------------------------------------- }
class function TMFMatrix3d.TypeName: string;
begin
Result := 'MFMatrix3d';
end;
{ TMFMatrix4f ------------------------------------------------------------------- }
class function TMFMatrix4f.TypeName: string;
begin
Result := 'MFMatrix4f';
end;
{ TMFMatrix4d ------------------------------------------------------------------- }
class function TMFMatrix4d.TypeName: string;
begin
Result := 'MFMatrix4d';
end;
{ TMFVec2f ------------------------------------------------------------------- }
class function TMFVec2f.TypeName: string;
begin
Result := 'MFVec2f';
end;
{ TMFVec3f ------------------------------------------------------------------- }
class function TMFVec3f.TypeName: string;
begin
Result := 'MFVec3f';
end;
{ TMFColor ------------------------------------------------------------------- }
class function TMFColor.TypeName: string;
begin
Result := 'MFColor';
end;
procedure TMFColor.Send(const AValue: array of TVector3Single);
var
FieldValue: TX3DField;
begin
FieldValue := TMFColor.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TMFColor.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TMFColorEvent.Create(AParentNode, AName, AInEvent);
end;
{ TMFVec4f ------------------------------------------------------------------- }
class function TMFVec4f.TypeName: string;
begin
Result := 'MFVec4f';
end;
{ TMFColorRGBA --------------------------------------------------------------- }
class function TMFColorRGBA.TypeName: string;
begin
Result := 'MFColorRGBA';
end;
procedure TMFColorRGBA.Send(const AValue: array of TVector4Single);
var
FieldValue: TX3DField;
begin
FieldValue := TMFColorRGBA.Create(ParentNode, Name, AValue);
try
Send(FieldValue);
finally FreeAndNil(FieldValue) end;
end;
class function TMFColorRGBA.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TMFColorRGBAEvent.Create(AParentNode, AName, AInEvent);
end;
{ TMFVec2d ------------------------------------------------------------------- }
class function TMFVec2d.TypeName: string;
begin
Result := 'MFVec2d';
end;
{ TMFVec3d ------------------------------------------------------------------- }
class function TMFVec3d.TypeName: string;
begin
Result := 'MFVec3d';
end;
{ TMFVec4d ------------------------------------------------------------------- }
class function TMFVec4d.TypeName: string;
begin
Result := 'MFVec4d';
end;
{ TMFRotation ---------------------------------------------------------------- }
class function TMFRotation.TypeName: string;
begin
Result := 'MFRotation';
end;
{ TMFFloat ------------------------------------------------------------------- }
function TMFFloat.SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean;
begin
Result := false;
end;
function TMFFloat.RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string;
begin
Result := FloatToRawStr(Items[ItemNum]);
end;
procedure TMFFloat.AssignLerp(const A: Double; Value1, Value2: TX3DField);
var
I: Integer;
Val1, Val2: TMFFloat;
begin
Val1 := Value1 as TMFFloat;
Val2 := Value2 as TMFFloat;
Val1.CheckCountEqual(Val2);
Items.Count := Val1.Items.Count;
for I := 0 to Items.Count - 1 do
Items[I] := Lerp(A, Val1.Items[I], Val2.Items[I]);
end;
function TMFFloat.CanAssignLerp: boolean;
begin
Result := true;
end;
class function TMFFloat.TypeName: string;
begin
Result := 'MFFloat';
end;
function TMFFloat.CreateItemBeforeParse: TX3DSingleField;
begin
Result := inherited;
{ Assign our Angle to single item used for parsing.
This way float values on MFFloat fields will be correctly converted to radians,
important e.g. for Background.skyAngle,groundAngle. }
(Result as TSFFloat).Angle := Angle;
end;
{ TMFDouble -------------------------------------------------------------------- }
function TMFDouble.SaveToStreamDoNewLineAfterRawItem(ItemNum: integer): boolean;
begin
Result := false;
end;
function TMFDouble.RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string;
begin
Result := FloatToRawStr(Items[ItemNum]);
end;
procedure TMFDouble.AssignLerp(const A: Double; Value1, Value2: TX3DField);
var
I: Integer;
Val1, Val2: TMFDouble;
begin
Val1 := Value1 as TMFDouble;
Val2 := Value2 as TMFDouble;
Val1.CheckCountEqual(Val2);
Items.Count := Val1.Items.Count;
for I := 0 to Items.Count - 1 do
Items[I] := Lerp(A, Val1.Items[I], Val2.Items[I]);
end;
function TMFDouble.CanAssignLerp: boolean;
begin
Result := true;
end;
class function TMFDouble.TypeName: string;
begin
Result := 'MFDouble';
end;
{ TMFTime -------------------------------------------------------------------- }
class function TMFTime.TypeName: string;
begin
Result := 'MFTime';
end;
class function TMFTime.CreateEvent(const AParentNode: TX3DFileItem; const AName: string; const AInEvent: boolean): TX3DEvent;
begin
Result := TMFTimeEvent.Create(AParentNode, AName, AInEvent);
end;
{ TMFString ------------------------------------------------------------------ }
function TMFString.RawItemToString(ItemNum: integer; const Encoding: TX3DEncoding): string;
begin
case Encoding of
xeClassic: Result := StringToX3DClassic(Items[ItemNum]);
xeXML : Result := StringToX3DXmlMulti(Items[ItemNum]);
else raise EInternalError.Create('TMFString.RawItemToString Encoding?');
end;
end;
class function TMFString.TypeName: string;
begin
Result := 'MFString';
end;
procedure TMFString.ParseXMLAttribute(const AttributeValue: string; Reader: TX3DReader);
var
Lexer: TX3DLexer;
begin
{ For MFString, it's very common that normal parsing fails because
of missing double quotes, even in models from
http://www.web3d.org/x3d/content/examples/Basic/
Although specification clearly says that MFString
components should always be enclosed within double
quotes. We just do what Xj3D seems to do, that is
we handle this as a single string (producing a warning). }
Lexer := TX3DLexer.CreateForPartialStream(AttributeValue, Reader.Version);
try
try
ParseXMLAttributeLexer(Lexer, Reader);
except
on E: EX3DClassicReadError do
begin
OnWarning(wtMajor, 'VRML/X3D', 'Error when reading MFString field "' + Name + '" value, probably missing double quotes (treating as a single string): ' + E.Message);
Items.Count := 0;
Items.Add(AttributeValue);
end;
end;
finally FreeAndNil(Lexer) end;
end;
function TMFString.SaveToXmlValue: TSaveToXmlMethod;
begin
Result := sxAttributeCustomQuotes;
end;
procedure TMFString.SaveToStreamValue(Writer: TX3DWriter);
begin
{ MFString in XML encoding is surrounded by single quotes }
if Writer.Encoding = xeXML then Writer.Write('''');
inherited;
if Writer.Encoding = xeXML then Writer.Write('''');
end;
{ TX3DFieldsManager --------------------------------------------------------- }
constructor TX3DFieldsManager.Create;
begin
inherited;
Registered := TStringList.Create;
{ All VRML/X3D names are case-sensitive. }
Registered.CaseSensitive := true;
end;
destructor TX3DFieldsManager.Destroy;
begin
FreeAndNil(Registered);
inherited;
end;
procedure TX3DFieldsManager.RegisterClass(AClass: TX3DFieldClass);
begin
Registered.AddObject(AClass.TypeName, TObject(AClass));
end;
procedure TX3DFieldsManager.RegisterClasses(
const Classes: array of TX3DFieldClass);
var
I: Integer;
begin
for I := 0 to High(Classes) do
RegisterClass(Classes[I]);
end;
function TX3DFieldsManager.FieldTypeNameToClass(
const TypeName: string): TX3DFieldClass;
var
I: Integer;
begin
I := Registered.IndexOf(TypeName);
if I <> -1 then
Result := TX3DFieldClass(Registered.Objects[I]) else
Result := nil;
end;
var
FX3DFieldsManager: TX3DFieldsManager;
function X3DFieldsManager: TX3DFieldsManager;
{ This function automatically creates FX3DFieldsManager instance.
I don't do this in initialization of this unit, since (because
of circular uses clauses) X3DFieldsManager may be referenced
before our initialization (e.g. by initialization of X3DNodes). }
begin
if FX3DFieldsManager = nil then
FX3DFieldsManager := TX3DFieldsManager.Create;
Result := FX3DFieldsManager;
end;
{ global utilities ----------------------------------------------------------- }
function X3DChangesToStr(const Changes: TX3DChanges): string;
var
C: TX3DChange;
begin
Result := '';
for C := Low(C) to High(C) do
if C in Changes then
begin
if Result <> '' then Result += ',';
Result += X3DChangeToStr[C];
end;
Result := '[' + Result + ']';
end;
initialization
X3DFieldsManager.RegisterClasses([
TSFBitMask,
TSFEnum,
TSFBool, TMFBool,
TSFFloat, TMFFloat,
TSFImage,
TSFLong, TMFLong,
TSFInt32, TMFInt32,
TSFMatrix3f, TMFMatrix3f,
TSFMatrix,
TSFMatrix3d, TMFMatrix3d,
TSFMatrix4f, TMFMatrix4f,
TSFMatrix4d, TMFMatrix4d,
TSFRotation, TMFRotation,
TSFString, TMFString,
TSFDouble, TMFDouble,
TSFTime, TMFTime,
TSFVec2f, TMFVec2f,
TSFVec3f, TMFVec3f,
TSFColor, TMFColor,
TSFVec4f, TMFVec4f,
TSFVec2d, TMFVec2d,
TSFVec3d, TMFVec3d,
TSFVec4d, TMFVec4d,
TSFColorRGBA,TMFColorRGBA
]);
finalization
FreeAndNil(FX3DFieldsManager);
end.
|