History

Starting on materials attributes, fixed bug with Hermite deltas.

Andrzej Kapolka committed 12 years ago

Commit 0bd800f1 parent 33faffd3 files · +30 −3Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+26−1
@@ -1828,6 +1828,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1827 unmodified lines
18281828 }
18291829 glm::vec3 center;
18301830 glm::vec3 normal;
1831+ const int MAX_MATERIALS_PER_VERTEX = 4;
1832+ quint8 materials[4];
1833+ glm::vec4 materialWeights;
1834+ float totalWeight = 0.0f;
18311835 int red = 0, green = 0, blue = 0;
18321836 for (int i = 0; i < crossingCount; i++) {
18331837 const EdgeCrossing& crossing = crossings[i];
@@ -1836,13 +1840,34 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines
18361840 red += qRed(crossing.color);
18371841 green += qGreen(crossing.color);
18381842 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+ }
18391858 }
18401859 normal = glm::normalize(normal);
18411860 center /= crossingCount;
1861+ if (totalWeight > 0.0f) {
1862+ materialWeights *= (EIGHT_BIT_MAXIMUM / totalWeight);
1863+ }
18421864 VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +
18431865 center * EIGHT_BIT_MAXIMUM_RECIPROCAL) * scale,
18441866 { (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] } };
18461871 int index = vertices.size();
18471872 vertices.append(point);
18481873

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t