Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1828,6 +1828,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1827 unmodified lines | ||
| 1828 | 1828 | } |
| 1829 | 1829 | glm::vec3 center; |
| 1830 | 1830 | glm::vec3 normal; |
| 1831 | + const int MAX_MATERIALS_PER_VERTEX = 4; | |
| 1832 | + quint8 materials[4]; | |
| 1833 | + glm::vec4 materialWeights; | |
| 1834 | + float totalWeight = 0.0f; | |
| 1831 | 1835 | int red = 0, green = 0, blue = 0; |
| 1832 | 1836 | for (int i = 0; i < crossingCount; i++) { |
| 1833 | 1837 | const EdgeCrossing& crossing = crossings[i]; |
| @@ -1836,13 +1840,34 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines | ||
| 1836 | 1840 | red += qRed(crossing.color); |
| 1837 | 1841 | green += qGreen(crossing.color); |
| 1838 | 1842 | blue += qBlue(crossing.color); |
| 1843 | + if (crossing.material != 0) { | |
| 1844 | + for (int j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) { | |
| 1845 | + if (materials[j] == crossing.material) { | |
| 1846 | + materialWeights[j] += 1.0f; | |
| 1847 | + totalWeight += 1.0f; | |
| 1848 | + break; | |
| 1849 | + | |
| 1850 | + } else if (materials[j] == 0.0f) { | |
| 1851 | + materials[j] = crossing.material; | |
| 1852 | + materialWeights[j] = 1.0f; | |
| 1853 | + totalWeight += 1.0f; | |
| 1854 | + break; | |
| 1855 | + } | |
| 1856 | + } | |
| 1857 | + } | |
| 1839 | 1858 | } |
| 1840 | 1859 | normal = glm::normalize(normal); |
| 1841 | 1860 | center /= crossingCount; |
| 1861 | + if (totalWeight > 0.0f) { | |
| 1862 | + materialWeights *= (EIGHT_BIT_MAXIMUM / totalWeight); | |
| 1863 | + } | |
| 1842 | 1864 | VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) + |
| 1843 | 1865 | center * EIGHT_BIT_MAXIMUM_RECIPROCAL) * scale, |
| 1844 | 1866 | { (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) }, |
| 1845 | − { (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) } }; | |
| 1867 | + { (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) }, | |
| 1868 | + { materials[0], materials[1], materials[2], materials[3] }, | |
| 1869 | + { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2], | |
| 1870 | + (quint8)materialWeights[3] } }; | |
| 1846 | 1871 | int index = vertices.size(); |
| 1847 | 1872 | vertices.append(point); |
| 1848 | 1873 | |