mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +00:00
Merge branch 'main' into volume-renderer
This commit is contained in:
commit
305f44d1c6
70 changed files with 802 additions and 580 deletions
|
|
@ -41,6 +41,20 @@ void Mesh::addPlane(
|
|||
);
|
||||
}
|
||||
|
||||
void Mesh::addTriangle(
|
||||
const glm::vec3& a,
|
||||
const glm::vec3& b,
|
||||
const glm::vec3& c,
|
||||
const glm::vec3& norm,
|
||||
const glm::vec2& uvA,
|
||||
const glm::vec2& uvB,
|
||||
const glm::vec2& uvC
|
||||
) {
|
||||
vertices.push_back({a, uvA, norm});
|
||||
vertices.push_back({b, uvB, norm});
|
||||
vertices.push_back({c, uvC, norm});
|
||||
}
|
||||
|
||||
void Mesh::addRect(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,15 @@ namespace model {
|
|||
const glm::vec3& up,
|
||||
const glm::vec3& norm,
|
||||
const UVRegion& region
|
||||
);
|
||||
void addTriangle(
|
||||
const glm::vec3& a,
|
||||
const glm::vec3& b,
|
||||
const glm::vec3& c,
|
||||
const glm::vec3& norm,
|
||||
const glm::vec2& uvA,
|
||||
const glm::vec2& uvB,
|
||||
const glm::vec2& uvC
|
||||
);
|
||||
void addBox(const glm::vec3& pos, const glm::vec3& size);
|
||||
void addBox(
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ void BlocksRenderer::face(
|
|||
const glm::vec4(&lights)[4],
|
||||
const glm::vec4& tint
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ void BlocksRenderer::faceAO(
|
|||
const UVRegion& region,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ void BlocksRenderer::face(
|
|||
glm::vec4 tint,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -275,19 +275,6 @@ void BlocksRenderer::blockAABB(
|
|||
}
|
||||
}
|
||||
|
||||
static bool is_aligned(const glm::vec3& v, float e = 1e-6f) {
|
||||
if (std::abs(v.y) < e && std::abs(v.z) < e && std::abs(v.x) > e) {
|
||||
return true;
|
||||
}
|
||||
if (std::abs(v.x) < e && std::abs(v.z) < e && std::abs(v.y) > e) {
|
||||
return true;
|
||||
}
|
||||
if (std::abs(v.x) < e && std::abs(v.y) < e && std::abs(v.z) > e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BlocksRenderer::blockCustomModel(
|
||||
const glm::ivec3& icoord, const Block& block, blockstate states, bool lights, bool ao
|
||||
) {
|
||||
|
|
@ -304,14 +291,34 @@ void BlocksRenderer::blockCustomModel(
|
|||
Z = orient.axes[2];
|
||||
}
|
||||
|
||||
if (!block.rt.extended) {
|
||||
glm::ivec3 offsets[6] {
|
||||
{-1, 0, 0}, {0, -1, 0}, {0, 0, -1},
|
||||
{1, 0, 0}, {0, 1, 0}, {0, 0, 1},
|
||||
};
|
||||
bool culled = true;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (isOpen(icoord + offsets[i], block, variant)) {
|
||||
culled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (culled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& model = cache.getModel(block.rt.id, block.getVariantIndex(states.userbits));
|
||||
for (const auto& mesh : model.meshes) {
|
||||
if (vertexCount + mesh.vertices.size() >= capacity) {
|
||||
if (vertexCount + mesh.vertices.size() >= capacity
|
||||
|| indexCount + mesh.vertices.size() >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
bool shading = mesh.shading && !block.shadeless;
|
||||
for (int triangle = 0; triangle < mesh.vertices.size() / 3; triangle++) {
|
||||
|
||||
int trianglesCount = mesh.vertices.size() / 3;
|
||||
for (int triangle = 0; triangle < trianglesCount; triangle++) {
|
||||
auto r = mesh.vertices[triangle * 3 + (triangle % 2) * 2].coord -
|
||||
mesh.vertices[triangle * 3 + 1].coord;
|
||||
r = r.x * X + r.y * Y + r.z * Z;
|
||||
|
|
@ -328,8 +335,7 @@ void BlocksRenderer::blockCustomModel(
|
|||
vp = vp.x * X + vp.y * Y + vp.z * Z;
|
||||
|
||||
if (!block.rt.extended
|
||||
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)
|
||||
&& is_aligned(n)) {
|
||||
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -769,6 +775,10 @@ ChunkMesh BlocksRenderer::render(
|
|||
const Chunk* chunk, const VoxelsRenderVolume& volume
|
||||
) {
|
||||
build(chunk, volume);
|
||||
|
||||
assert(vertexCount <= capacity);
|
||||
assert(indexCount <= capacity);
|
||||
assert(denseIndexCount <= capacity);
|
||||
|
||||
return ChunkMesh{std::make_unique<Mesh<ChunkVertex>>(
|
||||
vertexBuffer.get(), vertexCount,
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ Decorator::Decorator(
|
|||
addParticles(def, pos);
|
||||
}
|
||||
});
|
||||
playerNamePreset.deserialize(engine.getResPaths().readCombinedObject(
|
||||
"presets/text3d/player_name.toml"
|
||||
));
|
||||
for (const auto& [id, player] : *level.players) {
|
||||
if (id == this->player.getId()) {
|
||||
continue;
|
||||
|
|
@ -63,9 +66,6 @@ Decorator::Decorator(
|
|||
player->getPosition()
|
||||
));
|
||||
}
|
||||
playerNamePreset.deserialize(engine.getResPaths().readCombinedObject(
|
||||
"presets/text3d/player_name.toml"
|
||||
));
|
||||
}
|
||||
|
||||
void Decorator::addParticles(const Block& def, const glm::ivec3& pos) {
|
||||
|
|
|
|||
|
|
@ -67,15 +67,6 @@ GUI::GUI(Engine& engine)
|
|||
|
||||
GUI::~GUI() = default;
|
||||
|
||||
void GUI::setPageLoader(PageLoaderFunc pageLoader) {
|
||||
this->pagesLoader = std::move(pageLoader);
|
||||
menu->setPageLoader(this->pagesLoader);
|
||||
}
|
||||
|
||||
PageLoaderFunc GUI::getPagesLoader() {
|
||||
return pagesLoader;
|
||||
}
|
||||
|
||||
std::shared_ptr<Menu> GUI::getMenu() {
|
||||
return menu;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,8 +62,6 @@ namespace gui {
|
|||
class Container;
|
||||
class Menu;
|
||||
|
||||
using PageLoaderFunc = std::function<std::shared_ptr<UINode>(const std::string&)>;
|
||||
|
||||
/// @brief The main UI controller
|
||||
class GUI {
|
||||
Engine& engine;
|
||||
|
|
@ -83,8 +81,6 @@ namespace gui {
|
|||
std::queue<runnable> postRunnables;
|
||||
std::vector<std::weak_ptr<UINode>> mouseOver;
|
||||
|
||||
PageLoaderFunc pagesLoader;
|
||||
|
||||
float tooltipTimer = 0.0f;
|
||||
float doubleClickTimer = 0.0f;
|
||||
float doubleClickDelay = 0.5f;
|
||||
|
|
@ -101,10 +97,6 @@ namespace gui {
|
|||
GUI(Engine& engine);
|
||||
~GUI();
|
||||
|
||||
void setPageLoader(PageLoaderFunc pageLoader);
|
||||
|
||||
PageLoaderFunc getPagesLoader();
|
||||
|
||||
/// @brief Get the main menu (Menu) node
|
||||
std::shared_ptr<Menu> getMenu();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue