Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 120 files). Show all
Unified · Split
| @@ -33,6 +33,7 @@ · 32 unmodified lines | |||
| 33 | 33 | ||
| 34 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) | 34 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) |
| 35 | REGISTER_META_OBJECT(SphereRenderer) | 35 | REGISTER_META_OBJECT(SphereRenderer) |
| 36 | REGISTER_META_OBJECT(CuboidRenderer) | ||
| 36 | REGISTER_META_OBJECT(StaticModelRenderer) | 37 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 37 | 38 | ||
| 38 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); | 39 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); |
| @@ -963,6 +964,12 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 924 unmodified lines | |||
| 963 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); | 964 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); |
| 964 | } | 965 | } |
| 965 | 966 | ||
| 967 | void VoxelPoint::setNormal(const glm::vec3& normal) { | ||
| 968 | this->normal[0] = (char)(normal.x * 127.0f); | ||
| 969 | this->normal[1] = (char)(normal.y * 127.0f); | ||
| 970 | this->normal[2] = (char)(normal.z * 127.0f); | ||
| 971 | } | ||
| 972 | |||
| 966 | VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, | 973 | VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, |
| 967 | const QVector<SharedObjectPointer>& materials) : | 974 | const QVector<SharedObjectPointer>& materials) : |
| 968 | _vertices(vertices), | 975 | _vertices(vertices), |
| @@ -1534,8 +1541,21 @@ public: · 565 unmodified lines | |||
| 1534 | glm::vec3 normal; | 1541 | glm::vec3 normal; |
| 1535 | QRgb color; | 1542 | QRgb color; |
| 1536 | char material; | 1543 | char material; |
| 1544 | int axis; | ||
| 1537 | }; | 1545 | }; |
| 1538 | 1546 | ||
| 1547 | class AxisIndex { | ||
| 1548 | public: | ||
| 1549 | int x, y, z; | ||
| 1550 | |||
| 1551 | AxisIndex(int x = -1, int y = -1, int z = -1) : x(x), y(y), z(z) { } | ||
| 1552 | }; | ||
| 1553 | |||
| 1554 | static glm::vec3 safeNormalize(const glm::vec3& vector) { | ||
| 1555 | float length = glm::length(vector); | ||
| 1556 | return (length > 0.0f) ? (vector / length) : vector; | ||
| 1557 | } | ||
| 1558 | |||
| 1539 | int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { | 1559 | int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { |
| 1540 | if (!info.isLeaf) { | 1560 | if (!info.isLeaf) { |
| 1541 | return DEFAULT_ORDER; | 1561 | return DEFAULT_ORDER; |
| @@ -1574,10 +1594,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 32 unmodified lines | |||
| 1574 | // as we scan down the cube generating vertices between grid points, we remember the indices of the last | 1594 | // as we scan down the cube generating vertices between grid points, we remember the indices of the last |
| 1575 | // (element, line, section--x, y, z) so that we can connect generated vertices as quads | 1595 | // (element, line, section--x, y, z) so that we can connect generated vertices as quads |
| 1576 | int expanded = size + 1; | 1596 | int expanded = size + 1; |
| 1577 | QVector<int> lineIndices(expanded, -1); | 1597 | QVector<AxisIndex> lineIndices(expanded); |
| 1578 | QVector<int> lastLineIndices(expanded, -1); | 1598 | QVector<AxisIndex> lastLineIndices(expanded); |
| 1579 | QVector<int> planeIndices(expanded * expanded, -1); | 1599 | QVector<AxisIndex> planeIndices(expanded * expanded); |
| 1580 | QVector<int> lastPlaneIndices(expanded * expanded, -1); | 1600 | QVector<AxisIndex> lastPlaneIndices(expanded * expanded); |
| 1581 | 1601 | ||
| 1582 | const int EDGES_PER_CUBE = 12; | 1602 | const int EDGES_PER_CUBE = 12; |
| 1583 | EdgeCrossing crossings[EDGES_PER_CUBE]; | 1603 | EdgeCrossing crossings[EDGES_PER_CUBE]; |
| @@ -1588,7 +1608,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 4 unmodified lines | |||
| 1588 | for (int z = 0; z < expanded; z++) { | 1608 | for (int z = 0; z < expanded; z++) { |
| 1589 | const QRgb* colorY = colorZ; | 1609 | const QRgb* colorY = colorZ; |
| 1590 | for (int y = 0; y < expanded; y++) { | 1610 | for (int y = 0; y < expanded; y++) { |
| 1591 | int lastIndex = 0; | 1611 | AxisIndex lastIndex; |
| 1592 | const QRgb* colorX = colorY; | 1612 | const QRgb* colorX = colorY; |
| 1593 | for (int x = 0; x < expanded; x++) { | 1613 | for (int x = 0; x < expanded; x++) { |
| 1594 | int alpha0 = colorX[0] >> ALPHA_OFFSET; | 1614 | int alpha0 = colorX[0] >> ALPHA_OFFSET; |
| @@ -1662,6 +1682,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 67 unmodified lines | |||
| 1662 | crossing.material = materialBase[0]; | 1682 | crossing.material = materialBase[0]; |
| 1663 | } | 1683 | } |
| 1664 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); | 1684 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); |
| 1685 | crossing.axis = 0; | ||
| 1665 | } | 1686 | } |
| 1666 | if (middleY) { | 1687 | if (middleY) { |
| 1667 | if (alpha1 != alpha3) { | 1688 | if (alpha1 != alpha3) { |
| @@ -1676,6 +1697,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | |||
| 1676 | crossing.material = materialBase[1]; | 1697 | crossing.material = materialBase[1]; |
| 1677 | } | 1698 | } |
| 1678 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | 1699 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); |
| 1700 | crossing.axis = 1; | ||
| 1679 | } | 1701 | } |
| 1680 | if (alpha2 != alpha3) { | 1702 | if (alpha2 != alpha3) { |
| 1681 | QRgb hermite = hermiteBase[hermiteStride]; | 1703 | QRgb hermite = hermiteBase[hermiteStride]; |
| @@ -1689,6 +1711,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 1689 | crossing.material = materialBase[size]; | 1711 | crossing.material = materialBase[size]; |
| 1690 | } | 1712 | } |
| 1691 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); | 1713 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); |
| 1714 | crossing.axis = 0; | ||
| 1692 | } | 1715 | } |
| 1693 | if (middleZ) { | 1716 | if (middleZ) { |
| 1694 | if (alpha3 != alpha7) { | 1717 | if (alpha3 != alpha7) { |
| @@ -1703,6 +1726,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | |||
| 1703 | crossing.material = materialBase[offset3]; | 1726 | crossing.material = materialBase[offset3]; |
| 1704 | } | 1727 | } |
| 1705 | crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | 1728 | crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1729 | crossing.axis = 2; | ||
| 1706 | } | 1730 | } |
| 1707 | if (alpha5 != alpha7) { | 1731 | if (alpha5 != alpha7) { |
| 1708 | QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1]; | 1732 | QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1]; |
| @@ -1716,6 +1740,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 1716 | crossing.material = materialBase[offset5]; | 1740 | crossing.material = materialBase[offset5]; |
| 1717 | } | 1741 | } |
| 1718 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | 1742 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); |
| 1743 | crossing.axis = 1; | ||
| 1719 | } | 1744 | } |
| 1720 | if (alpha6 != alpha7) { | 1745 | if (alpha6 != alpha7) { |
| 1721 | QRgb hermite = hermiteBase[hermiteArea + hermiteStride]; | 1746 | QRgb hermite = hermiteBase[hermiteArea + hermiteStride]; |
| @@ -1729,6 +1754,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 1729 | crossing.material = materialBase[offset6]; | 1754 | crossing.material = materialBase[offset6]; |
| 1730 | } | 1755 | } |
| 1731 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); | 1756 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); |
| 1757 | crossing.axis = 0; | ||
| 1732 | } | 1758 | } |
| 1733 | } | 1759 | } |
| 1734 | } | 1760 | } |
| @@ -1745,6 +1771,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines | |||
| 1745 | crossing.material = materialBase[1]; | 1771 | crossing.material = materialBase[1]; |
| 1746 | } | 1772 | } |
| 1747 | crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | 1773 | crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1774 | crossing.axis = 2; | ||
| 1748 | } | 1775 | } |
| 1749 | if (alpha4 != alpha5) { | 1776 | if (alpha4 != alpha5) { |
| 1750 | QRgb hermite = hermiteBase[hermiteArea]; | 1777 | QRgb hermite = hermiteBase[hermiteArea]; |
| @@ -1758,6 +1785,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 1758 | crossing.material = materialBase[area]; | 1785 | crossing.material = materialBase[area]; |
| 1759 | } | 1786 | } |
| 1760 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); | 1787 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); |
| 1788 | crossing.axis = 0; | ||
| 1761 | } | 1789 | } |
| 1762 | } | 1790 | } |
| 1763 | } | 1791 | } |
| @@ -1774,6 +1802,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines | |||
| 1774 | crossing.material = materialBase[0]; | 1802 | crossing.material = materialBase[0]; |
| 1775 | } | 1803 | } |
| 1776 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | 1804 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); |
| 1805 | crossing.axis = 1; | ||
| 1777 | } | 1806 | } |
| 1778 | if (middleZ) { | 1807 | if (middleZ) { |
| 1779 | if (alpha2 != alpha6) { | 1808 | if (alpha2 != alpha6) { |
| @@ -1788,6 +1817,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | |||
| 1788 | crossing.material = materialBase[size]; | 1817 | crossing.material = materialBase[size]; |
| 1789 | } | 1818 | } |
| 1790 | crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | 1819 | crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1820 | crossing.axis = 2; | ||
| 1791 | } | 1821 | } |
| 1792 | if (alpha4 != alpha6) { | 1822 | if (alpha4 != alpha6) { |
| 1793 | QRgb hermite = hermiteBase[hermiteArea + 1]; | 1823 | QRgb hermite = hermiteBase[hermiteArea + 1]; |
| @@ -1801,6 +1831,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 1801 | crossing.material = materialBase[area]; | 1831 | crossing.material = materialBase[area]; |
| 1802 | } | 1832 | } |
| 1803 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | 1833 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); |
| 1834 | crossing.axis = 1; | ||
| 1804 | } | 1835 | } |
| 1805 | } | 1836 | } |
| 1806 | } | 1837 | } |
| @@ -1816,11 +1847,12 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 9 unmodified lines | |||
| 1816 | crossing.material = materialBase[0]; | 1847 | crossing.material = materialBase[0]; |
| 1817 | } | 1848 | } |
| 1818 | crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | 1849 | crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1850 | crossing.axis = 2; | ||
| 1819 | } | 1851 | } |
| 1820 | // at present, we simply average the properties of each crossing as opposed to finding the vertex that | 1852 | // at present, we simply average the properties of each crossing as opposed to finding the vertex that |
| 1821 | // minimizes the quadratic error function as described in the reference paper | 1853 | // minimizes the quadratic error function as described in the reference paper |
| 1822 | glm::vec3 center; | 1854 | glm::vec3 center; |
| 1823 | glm::vec3 normal; | 1855 | glm::vec3 axisNormals[3]; |
| 1824 | const int MAX_MATERIALS_PER_VERTEX = 4; | 1856 | const int MAX_MATERIALS_PER_VERTEX = 4; |
| 1825 | quint8 materials[] = { 0, 0, 0, 0 }; | 1857 | quint8 materials[] = { 0, 0, 0, 0 }; |
| 1826 | glm::vec4 materialWeights; | 1858 | glm::vec4 materialWeights; |
| @@ -1829,7 +1861,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines | |||
| 1829 | for (int i = 0; i < crossingCount; i++) { | 1861 | for (int i = 0; i < crossingCount; i++) { |
| 1830 | const EdgeCrossing& crossing = crossings[i]; | 1862 | const EdgeCrossing& crossing = crossings[i]; |
| 1831 | center += crossing.point; | 1863 | center += crossing.point; |
| 1832 | normal += crossing.normal; | 1864 | axisNormals[crossing.axis] += crossing.normal; |
| 1833 | red += qRed(crossing.color); | 1865 | red += qRed(crossing.color); |
| 1834 | green += qGreen(crossing.color); | 1866 | green += qGreen(crossing.color); |
| 1835 | blue += qBlue(crossing.color); | 1867 | blue += qBlue(crossing.color); |
| @@ -1852,16 +1884,18 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 16 unmodified lines | |||
| 1852 | } | 1884 | } |
| 1853 | } | 1885 | } |
| 1854 | } | 1886 | } |
| 1855 | normal = glm::normalize(normal); | 1887 | glm::vec3 normal = safeNormalize(axisNormals[0] + axisNormals[1] + axisNormals[2]); |
| 1856 | center /= crossingCount; | 1888 | center /= crossingCount; |
| 1857 | 1889 | ||
| 1858 | // use a sequence of Givens rotations to perform a QR decomposition | 1890 | // use a sequence of Givens rotations to perform a QR decomposition |
| 1859 | // see http://www.cs.rice.edu/~jwarren/papers/techreport02408.pdf | 1891 | // see http://www.cs.rice.edu/~jwarren/papers/techreport02408.pdf |
| 1860 | glm::mat4 r(0.0f); | 1892 | glm::mat4 r(0.0f); |
| 1861 | glm::vec4 bottom; | 1893 | glm::vec4 bottom; |
| 1894 | float smallestCosNormal = 1.0f; | ||
| 1862 | for (int i = 0; i < crossingCount; i++) { | 1895 | for (int i = 0; i < crossingCount; i++) { |
| 1863 | const EdgeCrossing& crossing = crossings[i]; | 1896 | const EdgeCrossing& crossing = crossings[i]; |
| 1864 | bottom = glm::vec4(crossing.normal, glm::dot(crossing.normal, crossing.point - center)); | 1897 | bottom = glm::vec4(crossing.normal, glm::dot(crossing.normal, crossing.point - center)); |
| 1898 | smallestCosNormal = qMin(smallestCosNormal, glm::dot(crossing.normal, normal)); | ||
| 1865 | 1899 | ||
| 1866 | for (int j = 0; j < 4; j++) { | 1900 | for (int j = 0; j < 4; j++) { |
| 1867 | float angle = glm::atan(-bottom[j], r[j][j]); | 1901 | float angle = glm::atan(-bottom[j], r[j][j]); |
| @@ -1899,12 +1933,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 31 unmodified lines | |||
| 1899 | int largestI = (largestIndex == 0) ? 1 : 2; | 1933 | int largestI = (largestIndex == 0) ? 1 : 2; |
| 1900 | float sjj = d[largestJ][largestJ]; | 1934 | float sjj = d[largestJ][largestJ]; |
| 1901 | float sii = d[largestI][largestI]; | 1935 | float sii = d[largestI][largestI]; |
| 1902 | float angle = (sii == sjj ? PI_OVER_TWO : glm::atan(2.0f * d[largestJ][largestI], sjj - sii)) / 2.0f; | 1936 | float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f; |
| 1903 | glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) : | 1937 | glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) : |
| 1904 | (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f))); | 1938 | (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f))); |
| 1905 | if (rotation.w == 0.0f) { | ||
| 1906 | break; | ||
| 1907 | } | ||
| 1908 | combinedRotation = glm::normalize(rotation * combinedRotation); | 1939 | combinedRotation = glm::normalize(rotation * combinedRotation); |
| 1909 | glm::mat3 matrix = glm::mat3_cast(combinedRotation); | 1940 | glm::mat3 matrix = glm::mat3_cast(combinedRotation); |
| 1910 | d = matrix * ata * glm::transpose(matrix); | 1941 | d = matrix * ata * glm::transpose(matrix); |
| @@ -1933,17 +1964,69 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 22 unmodified lines | |||
| 1933 | { materials[0], materials[1], materials[2], materials[3] }, | 1964 | { materials[0], materials[1], materials[2], materials[3] }, |
| 1934 | { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2], | 1965 | { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2], |
| 1935 | (quint8)materialWeights[3] } }; | 1966 | (quint8)materialWeights[3] } }; |
| 1936 | int index = vertices.size(); | 1967 | |
| 1937 | vertices.append(point); | 1968 | // determine whether we must "crease" by generating directional normals |
| 1969 | const float CREASE_COS_NORMAL = glm::cos(glm::radians(40.0f)); | ||
| 1970 | AxisIndex index(vertices.size(), vertices.size(), vertices.size()); | ||
| 1971 | if (smallestCosNormal > CREASE_COS_NORMAL) { | ||
| 1972 | vertices.append(point); | ||
| 1973 | |||
| 1974 | } else { | ||
| 1975 | axisNormals[0] = safeNormalize(axisNormals[0]); | ||
| 1976 | axisNormals[1] = safeNormalize(axisNormals[1]); | ||
| 1977 | axisNormals[2] = safeNormalize(axisNormals[2]); | ||
| 1978 | glm::vec3 normalXY(safeNormalize(axisNormals[0] + axisNormals[1])); | ||
| 1979 | glm::vec3 normalXZ(safeNormalize(axisNormals[0] + axisNormals[2])); | ||
| 1980 | glm::vec3 normalYZ(safeNormalize(axisNormals[1] + axisNormals[2])); | ||
| 1981 | if (glm::dot(axisNormals[0], normalXY) > CREASE_COS_NORMAL && | ||
| 1982 | glm::dot(axisNormals[1], normalXY) > CREASE_COS_NORMAL) { | ||
| 1983 | point.setNormal(normalXY); | ||
| 1984 | vertices.append(point); | ||
| 1985 | |||
| 1986 | point.setNormal(axisNormals[2]); | ||
| 1987 | index.z = vertices.size(); | ||
| 1988 | vertices.append(point); | ||
| 1989 | |||
| 1990 | } else if (glm::dot(axisNormals[0], normalXZ) > CREASE_COS_NORMAL && | ||
| 1991 | glm::dot(axisNormals[2], normalXZ) > CREASE_COS_NORMAL) { | ||
| 1992 | point.setNormal(normalXZ); | ||
| 1993 | vertices.append(point); | ||
| 1994 | |||
| 1995 | point.setNormal(axisNormals[1]); | ||
| 1996 | index.y = vertices.size(); | ||
| 1997 | vertices.append(point); | ||
| 1998 | |||
| 1999 | } else if (glm::dot(axisNormals[1], normalYZ) > CREASE_COS_NORMAL && | ||
| 2000 | glm::dot(axisNormals[2], normalYZ) > CREASE_COS_NORMAL) { | ||
| 2001 | point.setNormal(normalYZ); | ||
| 2002 | vertices.append(point); | ||
| 2003 | |||
| 2004 | point.setNormal(axisNormals[0]); | ||
| 2005 | index.x = vertices.size(); | ||
| 2006 | vertices.append(point); | ||
| 2007 | |||
| 2008 | } else { | ||
| 2009 | point.setNormal(axisNormals[0]); | ||
| 2010 | vertices.append(point); | ||
| 2011 | |||
| 2012 | point.setNormal(axisNormals[1]); | ||
| 2013 | index.y = vertices.size(); | ||
| 2014 | vertices.append(point); | ||
| 2015 | |||
| 2016 | point.setNormal(axisNormals[2]); | ||
| 2017 | index.z = vertices.size(); | ||
| 2018 | vertices.append(point); | ||
| 2019 | } | ||
| 2020 | } | ||
| 1938 | 2021 | ||
| 1939 | // the first x, y, and z are repeated for the boundary edge; past that, we consider generating | 2022 | // the first x, y, and z are repeated for the boundary edge; past that, we consider generating |
| 1940 | // quads for each edge that includes a transition, using indices of previously generated vertices | 2023 | // quads for each edge that includes a transition, using indices of previously generated vertices |
| 1941 | if (x != 0 && y != 0 && z != 0) { | 2024 | if (x != 0 && y != 0 && z != 0) { |
| 1942 | if (alpha0 != alpha1) { | 2025 | if (alpha0 != alpha1) { |
| 1943 | indices.append(index); | 2026 | indices.append(index.x); |
| 1944 | int index1 = lastLineIndices.at(x); | 2027 | int index1 = lastLineIndices.at(x).x; |
| 1945 | int index2 = lastPlaneIndices.at((y - 1) * expanded + x); | 2028 | int index2 = lastPlaneIndices.at((y - 1) * expanded + x).x; |
| 1946 | int index3 = lastPlaneIndices.at(y * expanded + x); | 2029 | int index3 = lastPlaneIndices.at(y * expanded + x).x; |
| 1947 | if (alpha0 == 0) { // quad faces negative x | 2030 | if (alpha0 == 0) { // quad faces negative x |
| 1948 | indices.append(index3); | 2031 | indices.append(index3); |
| 1949 | indices.append(index2); | 2032 | indices.append(index2); |
| @@ -1956,10 +2039,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 6 unmodified lines | |||
| 1956 | } | 2039 | } |
| 1957 | 2040 | ||
| 1958 | if (alpha0 != alpha2) { | 2041 | if (alpha0 != alpha2) { |
| 1959 | indices.append(index); | 2042 | indices.append(index.y); |
| 1960 | int index1 = lastIndex; | 2043 | int index1 = lastIndex.y; |
| 1961 | int index2 = lastPlaneIndices.at(y * expanded + x - 1); | 2044 | int index2 = lastPlaneIndices.at(y * expanded + x - 1).y; |
| 1962 | int index3 = lastPlaneIndices.at(y * expanded + x); | 2045 | int index3 = lastPlaneIndices.at(y * expanded + x).y; |
| 1963 | if (alpha0 == 0) { // quad faces negative y | 2046 | if (alpha0 == 0) { // quad faces negative y |
| 1964 | indices.append(index1); | 2047 | indices.append(index1); |
| 1965 | indices.append(index2); | 2048 | indices.append(index2); |
| @@ -1972,10 +2055,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 6 unmodified lines | |||
| 1972 | } | 2055 | } |
| 1973 | 2056 | ||
| 1974 | if (alpha0 != alpha4) { | 2057 | if (alpha0 != alpha4) { |
| 1975 | indices.append(index); | 2058 | indices.append(index.z); |
| 1976 | int index1 = lastIndex; | 2059 | int index1 = lastIndex.z; |
| 1977 | int index2 = lastLineIndices.at(x - 1); | 2060 | int index2 = lastLineIndices.at(x - 1).z; |
| 1978 | int index3 = lastLineIndices.at(x); | 2061 | int index3 = lastLineIndices.at(x).z; |
| 1979 | if (alpha0 == 0) { // quad faces negative z | 2062 | if (alpha0 == 0) { // quad faces negative z |
| 1980 | indices.append(index3); | 2063 | indices.append(index3); |
| 1981 | indices.append(index2); | 2064 | indices.append(index2); |
| @@ -2119,7 +2202,8 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 137 unmodified lines | |||
| 2119 | } | 2202 | } |
| 2120 | 2203 | ||
| 2121 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { | 2204 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { |
| 2122 | spanner->getRenderer()->render(1.0f, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | 2205 | const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); |
| 2206 | spanner->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | ||
| 2123 | return true; | 2207 | return true; |
| 2124 | } | 2208 | } |
| 2125 | 2209 | ||
| @@ -2285,9 +2369,9 @@ static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { · 159 unmodified lines | |||
| 2285 | glEnable(plane); | 2369 | glEnable(plane); |
| 2286 | } | 2370 | } |
| 2287 | 2371 | ||
| 2288 | void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | 2372 | void ClippedRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { |
| 2289 | if (clipSize == 0.0f) { | 2373 | if (clipSize == 0.0f) { |
| 2290 | renderUnclipped(alpha, mode); | 2374 | renderUnclipped(color, mode); |
| 2291 | return; | 2375 | return; |
| 2292 | } | 2376 | } |
| 2293 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); | 2377 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); |
| @@ -2297,7 +2381,7 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 3 unmodified lines | |||
| 2297 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); | 2381 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); |
| 2298 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); | 2382 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); |
| 2299 | 2383 | ||
| 2300 | renderUnclipped(alpha, mode); | 2384 | renderUnclipped(color, mode); |
| 2301 | 2385 | ||
| 2302 | glDisable(GL_CLIP_PLANE0); | 2386 | glDisable(GL_CLIP_PLANE0); |
| 2303 | glDisable(GL_CLIP_PLANE1); | 2387 | glDisable(GL_CLIP_PLANE1); |
| @@ -2310,9 +2394,9 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 6 unmodified lines | |||
| 2310 | SphereRenderer::SphereRenderer() { | 2394 | SphereRenderer::SphereRenderer() { |
| 2311 | } | 2395 | } |
| 2312 | 2396 | ||
| 2313 | void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | 2397 | void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { |
| 2314 | if (clipSize == 0.0f) { | 2398 | if (clipSize == 0.0f) { |
| 2315 | renderUnclipped(alpha, mode); | 2399 | renderUnclipped(color, mode); |
| 2316 | return; | 2400 | return; |
| 2317 | } | 2401 | } |
| 2318 | // slight performance optimization: don't render if clip bounds are entirely within sphere | 2402 | // slight performance optimization: don't render if clip bounds are entirely within sphere |
| @@ -2321,29 +2405,50 @@ void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum · 2 unmodified lines | |||
| 2321 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { | 2405 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { |
| 2322 | const float CLIP_PROPORTION = 0.95f; | 2406 | const float CLIP_PROPORTION = 0.95f; |
| 2323 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { | 2407 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { |
| 2324 | ClippedRenderer::render(alpha, mode, clipMinimum, clipSize); | 2408 | ClippedRenderer::render(color, mode, clipMinimum, clipSize); |
| 2325 | return; | 2409 | return; |
| 2326 | } | 2410 | } |
| 2327 | } | 2411 | } |
| 2328 | } | 2412 | } |
| 2329 | 2413 | ||
| 2330 | void SphereRenderer::renderUnclipped(float alpha, Mode mode) { | 2414 | void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { |
| 2331 | Sphere* sphere = static_cast<Sphere*>(_spanner); | 2415 | Sphere* sphere = static_cast<Sphere*>(_spanner); |
| 2332 | const QColor& color = sphere->getColor(); | 2416 | const QColor& ownColor = sphere->getColor(); |
| 2333 | glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha); | 2417 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); |
| 2334 | 2418 | ||
| 2335 | glPushMatrix(); | 2419 | glPushMatrix(); |
| 2336 | const glm::vec3& translation = sphere->getTranslation(); | 2420 | const glm::vec3& translation = sphere->getTranslation(); |
| 2337 | glTranslatef(translation.x, translation.y, translation.z); | 2421 | glTranslatef(translation.x, translation.y, translation.z); |
| 2338 | glm::quat rotation = sphere->getRotation(); | 2422 | glm::quat rotation = sphere->getRotation(); |
| 2339 | glm::vec3 axis = glm::axis(rotation); | 2423 | glm::vec3 axis = glm::axis(rotation); |
| 2340 | glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); | 2424 | glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); |
| 2341 | 2425 | ||
| 2342 | Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10); | 2426 | Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10); |
| 2343 | 2427 | ||
| 2344 | glPopMatrix(); | 2428 | glPopMatrix(); |
| 2345 | } | 2429 | } |
| 2346 | 2430 | ||
| 2431 | CuboidRenderer::CuboidRenderer() { | ||
| 2432 | } | ||
| 2433 | |||
| 2434 | void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | ||
| 2435 | Cuboid* cuboid = static_cast<Cuboid*>(_spanner); | ||
| 2436 | const QColor& ownColor = cuboid->getColor(); | ||
| 2437 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | ||
| 2438 | |||
| 2439 | glPushMatrix(); | ||
| 2440 | const glm::vec3& translation = cuboid->getTranslation(); | ||
| 2441 | glTranslatef(translation.x, translation.y, translation.z); | ||
| 2442 | glm::quat rotation = cuboid->getRotation(); | ||
| 2443 | glm::vec3 axis = glm::axis(rotation); | ||
| 2444 | glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); | ||
| 2445 | glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ()); | ||
| 2446 | |||
| 2447 | glutSolidCube(cuboid->getScale() * 2.0f); | ||
| 2448 | |||
| 2449 | glPopMatrix(); | ||
| 2450 | } | ||
| 2451 | |||
| 2347 | StaticModelRenderer::StaticModelRenderer() : | 2452 | StaticModelRenderer::StaticModelRenderer() : |
| 2348 | _model(new Model(this)) { | 2453 | _model(new Model(this)) { |
| 2349 | } | 2454 | } |
| @@ -2377,21 +2482,21 @@ void StaticModelRenderer::simulate(float deltaTime) { · 27 unmodified lines | |||
| 2377 | _model->simulate(deltaTime); | 2482 | _model->simulate(deltaTime); |
| 2378 | } | 2483 | } |
| 2379 | 2484 | ||
| 2380 | void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) { | 2485 | void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { |
| 2381 | switch (mode) { | 2486 | switch (mode) { |
| 2382 | case DIFFUSE_MODE: | 2487 | case DIFFUSE_MODE: |
| 2383 | _model->render(alpha, Model::DIFFUSE_RENDER_MODE); | 2488 | _model->render(color.a, Model::DIFFUSE_RENDER_MODE); |
| 2384 | break; | 2489 | break; |
| 2385 | 2490 | ||
| 2386 | case NORMAL_MODE: | 2491 | case NORMAL_MODE: |
| 2387 | _model->render(alpha, Model::NORMAL_RENDER_MODE); | 2492 | _model->render(color.a, Model::NORMAL_RENDER_MODE); |
| 2388 | break; | 2493 | break; |
| 2389 | 2494 | ||
| 2390 | default: | 2495 | default: |
| 2391 | _model->render(alpha); | 2496 | _model->render(color.a); |
| 2392 | break; | 2497 | break; |
| 2393 | } | 2498 | } |
| 2394 | _model->render(alpha); | 2499 | _model->render(color.a); |
| 2395 | } | 2500 | } |
| 2396 | 2501 | ||
| 2397 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, | 2502 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |