asdf
This commit is contained in:
@@ -14,7 +14,50 @@
|
|||||||
#include "../ray3.hpp"
|
#include "../ray3.hpp"
|
||||||
|
|
||||||
constexpr float EPSILON = 0.0000000000000000000000001;
|
constexpr float EPSILON = 0.0000000000000000000000001;
|
||||||
constexpr int CHUNK_SIZE = 64;
|
constexpr int CHUNK_SIZE = 16;
|
||||||
|
|
||||||
|
/// @brief Represents a single point in the grid with an ID, color, and position.
|
||||||
|
class GenericVoxel {
|
||||||
|
protected:
|
||||||
|
size_t id;
|
||||||
|
Vec4 color;
|
||||||
|
Vec3 pos;
|
||||||
|
public:
|
||||||
|
//constructors
|
||||||
|
GenericVoxel(size_t id, Vec4 color, Vec3 pos) : id(id), color(color), pos(pos) {};
|
||||||
|
GenericVoxel() : id(0), color(Vec4()), pos(Vec3()) {};
|
||||||
|
|
||||||
|
//getters
|
||||||
|
size_t getId() const {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
Vec3 getPos() const {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4 getColor() const {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//setters
|
||||||
|
void setColor(Vec4 newColor) {
|
||||||
|
color = newColor;
|
||||||
|
}
|
||||||
|
void setPos(Vec3 newPos) {
|
||||||
|
pos = newPos;
|
||||||
|
}
|
||||||
|
void setId(size_t newId) {
|
||||||
|
id = newId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void move(Vec3 newPos) {
|
||||||
|
pos = newPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void recolor(Vec4 newColor) {
|
||||||
|
color.recolor(newColor);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief A bidirectional lookup helper to map internal IDs to 2D positions and vice-versa.
|
/// @brief A bidirectional lookup helper to map internal IDs to 2D positions and vice-versa.
|
||||||
/// @details Maintains two hashmaps to allow O(1) lookup in either direction.
|
/// @details Maintains two hashmaps to allow O(1) lookup in either direction.
|
||||||
@@ -129,10 +172,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Chunk3 {
|
class Chunk3 : GenericVoxel {
|
||||||
private:
|
private:
|
||||||
Vec3 chunkCoord;
|
Vec3 chunkCoord;
|
||||||
std::unordered_set<size_t> voxelIDs;
|
std::unordered_set<size_t> voxelIDs;
|
||||||
|
std::vector<GenericVoxel> storedValues;
|
||||||
|
bool isCompressed = false;
|
||||||
|
int detailLevel;
|
||||||
|
std::vector<GenericVoxel> fullVoxels;
|
||||||
public:
|
public:
|
||||||
Chunk3(const Vec3& coord) : chunkCoord(coord) {}
|
Chunk3(const Vec3& coord) : chunkCoord(coord) {}
|
||||||
|
|
||||||
@@ -156,6 +203,13 @@ public:
|
|||||||
auto [minBound, _] = getBounds();
|
auto [minBound, _] = getBounds();
|
||||||
return worldPos - minBound;
|
return worldPos - minBound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<uint8_t> compress() {
|
||||||
|
for (auto value : storedValues) {
|
||||||
|
Vec4 sc = value.getColor() / CHUNK_SIZE;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Accelerates spatial queries by bucketizing positions into a grid.
|
/// @brief Accelerates spatial queries by bucketizing positions into a grid.
|
||||||
@@ -248,36 +302,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Represents a single point in the grid with an ID, color, and position.
|
|
||||||
class GenericVoxel {
|
|
||||||
protected:
|
|
||||||
size_t id;
|
|
||||||
Vec4 color;
|
|
||||||
Vec3 pos;
|
|
||||||
public:
|
|
||||||
//constructors
|
|
||||||
GenericVoxel(size_t id, Vec4 color, Vec3 pos) : id(id), color(color), pos(pos) {};
|
|
||||||
|
|
||||||
//getters
|
|
||||||
Vec4 getColor() const {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
//setters
|
|
||||||
void setColor(Vec4 newColor) {
|
|
||||||
color = newColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void move(Vec3 newPos) {
|
|
||||||
pos = newPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void recolor(Vec4 newColor) {
|
|
||||||
color.recolor(newColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Grid3 {
|
class Grid3 {
|
||||||
protected:
|
protected:
|
||||||
//all positions
|
//all positions
|
||||||
@@ -298,7 +322,7 @@ protected:
|
|||||||
bool regenpreventer = false;
|
bool regenpreventer = false;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Grid3 noiseGenGrid(Vec3 min, Vec3 max, float minChance = 0.1f
|
Grid3& noiseGenGrid(Vec3 min, Vec3 max, float minChance = 0.1f
|
||||||
, float maxChance = 1.0f, bool color = true, int noisemod = 42) {
|
, float maxChance = 1.0f, bool color = true, int noisemod = 42) {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
noisegen = PNoise2(noisemod);
|
noisegen = PNoise2(noisemod);
|
||||||
@@ -778,7 +802,7 @@ public:
|
|||||||
return neighbors;
|
return neighbors;
|
||||||
}
|
}
|
||||||
|
|
||||||
Grid3 backfillGrid() {
|
Grid3& backfillGrid() {
|
||||||
TIME_FUNCTION;
|
TIME_FUNCTION;
|
||||||
Vec3 Min;
|
Vec3 Min;
|
||||||
Vec3 Max;
|
Vec3 Max;
|
||||||
|
|||||||
Reference in New Issue
Block a user