mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
I believe this should be a better hash function for the voxel coordinates.
This commit is contained in:
parent
2adb519193
commit
87cc565c1a
2 changed files with 20 additions and 5 deletions
|
@ -1011,7 +1011,7 @@ void VoxelPoint::setNormal(const glm::vec3& normal) {
|
|||
}
|
||||
|
||||
VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite,
|
||||
const QMultiHash<QRgb, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) :
|
||||
const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials) :
|
||||
_vertices(vertices),
|
||||
_indices(indices),
|
||||
_hermite(hermite),
|
||||
|
@ -1056,7 +1056,7 @@ bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::ve
|
|||
int max = _size - 2;
|
||||
int x = qMin((int)floors.x, max), y = qMin((int)floors.y, max), z = qMin((int)floors.z, max);
|
||||
forever {
|
||||
for (QMultiHash<QRgb, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1));
|
||||
for (QMultiHash<VoxelCoord, int>::const_iterator it = _quadIndices.constFind(qRgb(x + 1, y + 1, z + 1));
|
||||
it != _quadIndices.constEnd(); it++) {
|
||||
const int* indices = _indices.constData() + *it;
|
||||
if (findRayTriangleIntersection(origin, direction, _vertices.at(indices[0]).vertex,
|
||||
|
@ -1311,7 +1311,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
|
|||
QVector<VoxelPoint> vertices;
|
||||
QVector<int> indices;
|
||||
QVector<glm::vec3> hermiteSegments;
|
||||
QMultiHash<QRgb, int> quadIndices;
|
||||
QMultiHash<VoxelCoord, int> quadIndices;
|
||||
|
||||
// see http://www.frankpetterson.com/publications/dualcontour/dualcontour.pdf for a description of the
|
||||
// dual contour algorithm for generating meshes from voxel data using Hermite-tagged edges
|
||||
|
|
|
@ -308,12 +308,27 @@ public:
|
|||
void setNormal(const glm::vec3& normal);
|
||||
};
|
||||
|
||||
/// A container for a coordinate within a voxel block.
|
||||
class VoxelCoord {
|
||||
public:
|
||||
QRgb encoded;
|
||||
|
||||
VoxelCoord(QRgb encoded) : encoded(encoded) { }
|
||||
|
||||
bool operator==(const VoxelCoord& other) const { return encoded == other.encoded; }
|
||||
};
|
||||
|
||||
inline uint qHash(const VoxelCoord& coord, uint seed) {
|
||||
// 31 is just an arbitrary prime number
|
||||
return qHash(qRed(coord.encoded) + 31 * (qGreen(coord.encoded) + 31 * qBlue(coord.encoded)), seed);
|
||||
}
|
||||
|
||||
/// Contains the information necessary to render a voxel block.
|
||||
class VoxelBuffer : public BufferData {
|
||||
public:
|
||||
|
||||
VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, const QVector<glm::vec3>& hermite,
|
||||
const QMultiHash<QRgb, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials =
|
||||
const QMultiHash<VoxelCoord, int>& quadIndices, int size, const QVector<SharedObjectPointer>& materials =
|
||||
QVector<SharedObjectPointer>());
|
||||
|
||||
/// Finds the first intersection between the described ray and the voxel data.
|
||||
|
@ -328,7 +343,7 @@ private:
|
|||
QVector<VoxelPoint> _vertices;
|
||||
QVector<int> _indices;
|
||||
QVector<glm::vec3> _hermite;
|
||||
QMultiHash<QRgb, int> _quadIndices;
|
||||
QMultiHash<VoxelCoord, int> _quadIndices;
|
||||
int _size;
|
||||
int _vertexCount;
|
||||
int _indexCount;
|
||||
|
|
Loading…
Reference in a new issue