diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 4b1bfa56ac..8de78cc5be 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -1828,6 +1828,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { } glm::vec3 center; glm::vec3 normal; + const int MAX_MATERIALS_PER_VERTEX = 4; + quint8 materials[4]; + glm::vec4 materialWeights; + float totalWeight = 0.0f; int red = 0, green = 0, blue = 0; for (int i = 0; i < crossingCount; i++) { const EdgeCrossing& crossing = crossings[i]; @@ -1836,13 +1840,34 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { red += qRed(crossing.color); green += qGreen(crossing.color); blue += qBlue(crossing.color); + if (crossing.material != 0) { + for (int j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) { + if (materials[j] == crossing.material) { + materialWeights[j] += 1.0f; + totalWeight += 1.0f; + break; + + } else if (materials[j] == 0.0f) { + materials[j] = crossing.material; + materialWeights[j] = 1.0f; + totalWeight += 1.0f; + break; + } + } + } } normal = glm::normalize(normal); center /= crossingCount; + if (totalWeight > 0.0f) { + materialWeights *= (EIGHT_BIT_MAXIMUM / totalWeight); + } VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) + center * EIGHT_BIT_MAXIMUM_RECIPROCAL) * scale, { (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) }, - { (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) } }; + { (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) }, + { materials[0], materials[1], materials[2], materials[3] }, + { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2], + (quint8)materialWeights[3] } }; int index = vertices.size(); vertices.append(point); diff --git a/interface/src/MetavoxelSystem.h b/interface/src/MetavoxelSystem.h index 3be00543c2..aa15dcc8db 100644 --- a/interface/src/MetavoxelSystem.h +++ b/interface/src/MetavoxelSystem.h @@ -220,6 +220,8 @@ public: glm::vec3 vertex; quint8 color[3]; char normal[3]; + quint8 materials[4]; + quint8 materialWeights[4]; }; /// Contains the information necessary to render a voxel block. diff --git a/libraries/metavoxels/src/AttributeRegistry.cpp b/libraries/metavoxels/src/AttributeRegistry.cpp index 70b9a1e343..aec9a069be 100644 --- a/libraries/metavoxels/src/AttributeRegistry.cpp +++ b/libraries/metavoxels/src/AttributeRegistry.cpp @@ -1907,8 +1907,8 @@ void VoxelHermiteData::writeDelta(Bitstream& out, const VoxelHermiteDataPointer& bool differenceZ = false; for (int y = 0; y < _size; y++) { bool differenceY = false; - for (int x = 0; x < _size; x++) { - if (*src++ != *ref++ || *src++ != *ref++ || *src++ != *ref++) { + for (int x = 0; x < _size; x++, src += EDGE_COUNT, ref += EDGE_COUNT) { + if (src[0] != ref[0] || src[1] != ref[1] || src[2] != ref[2]) { minX = qMin(minX, x); maxX = qMax(maxX, x); differenceY = differenceZ = true;