(ctx, width, height, viewScale)
| 1858 | // ============================================================================ |
| 1859 | |
| 1860 | function draw(ctx, width, height, viewScale) { |
| 1861 | PERF_START('draw'); |
| 1862 | |
| 1863 | const halfW = width / 2; |
| 1864 | const halfH = height / 2; |
| 1865 | |
| 1866 | |
| 1867 | // 3D Polys |
| 1868 | // --------------- |
| 1869 | ctx.lineJoin = 'bevel'; |
| 1870 | |
| 1871 | PERF_START('drawShadows'); |
| 1872 | ctx.fillStyle = shadowColor; |
| 1873 | ctx.strokeStyle = shadowColor; |
| 1874 | allShadowPolys.forEach(p => { |
| 1875 | if (p.wireframe) { |
| 1876 | ctx.lineWidth = 2; |
| 1877 | ctx.beginPath(); |
| 1878 | const { vertices } = p; |
| 1879 | const vCount = vertices.length; |
| 1880 | const firstV = vertices[0]; |
| 1881 | ctx.moveTo(firstV.x, firstV.y); |
| 1882 | for (let i=1; i<vCount; i++) { |
| 1883 | const v = vertices[i]; |
| 1884 | ctx.lineTo(v.x, v.y); |
| 1885 | } |
| 1886 | ctx.closePath(); |
| 1887 | ctx.stroke(); |
| 1888 | } else { |
| 1889 | ctx.beginPath(); |
| 1890 | const { vertices } = p; |
| 1891 | const vCount = vertices.length; |
| 1892 | const firstV = vertices[0]; |
| 1893 | ctx.moveTo(firstV.x, firstV.y); |
| 1894 | for (let i=1; i<vCount; i++) { |
| 1895 | const v = vertices[i]; |
| 1896 | ctx.lineTo(v.x, v.y); |
| 1897 | } |
| 1898 | ctx.closePath(); |
| 1899 | ctx.fill(); |
| 1900 | } |
| 1901 | }); |
| 1902 | PERF_END('drawShadows'); |
| 1903 | |
| 1904 | PERF_START('drawPolys'); |
| 1905 | |
| 1906 | allPolys.forEach(p => { |
| 1907 | if (!p.wireframe && p.normalCamera.z < 0) return; |
| 1908 | |
| 1909 | if (p.strokeWidth !== 0) { |
| 1910 | ctx.lineWidth = p.normalCamera.z < 0 ? p.strokeWidth * 0.5 : p.strokeWidth; |
| 1911 | ctx.strokeStyle = p.normalCamera.z < 0 ? p.strokeColorDark : p.strokeColor; |
| 1912 | } |
| 1913 | |
| 1914 | const { vertices } = p; |
| 1915 | const lastV = vertices[vertices.length - 1]; |
| 1916 | const fadeOut = p.middle.z > cameraFadeStartZ; |
| 1917 |
no test coverage detected