add src/coders/obj
This commit is contained in:
@@ -66,13 +66,19 @@ void ModelBatch::draw(const model::Model& model) {
|
||||
} else {
|
||||
blank->bind();
|
||||
}
|
||||
for (const auto& vert : mesh.vertices) {
|
||||
auto norm = rotation * vert.normal;
|
||||
float d = glm::dot(norm, SUN_VECTOR);
|
||||
d = 0.8f + d * 0.2f;
|
||||
|
||||
auto color = lights * d;
|
||||
vertex(vert.coord, vert.uv, color);
|
||||
for (size_t i = 0; i < mesh.vertices.size() / 3; i++) {
|
||||
if (index + VERTEX_SIZE * 3 > capacity) {
|
||||
flush();
|
||||
}
|
||||
for (size_t j = 0; j < 3; j++) {
|
||||
const auto& vert = mesh.vertices[i * 3 + j];
|
||||
auto norm = rotation * vert.normal;
|
||||
float d = glm::dot(norm, SUN_VECTOR);
|
||||
d = 0.8f + d * 0.2f;
|
||||
|
||||
auto color = lights * d;
|
||||
vertex(vert.coord, vert.uv, color);
|
||||
}
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
#include "../../assets/Assets.hpp"
|
||||
#include "../../content/Content.hpp"
|
||||
#include "../../engine.hpp"
|
||||
#include "../../coders/obj.hpp"
|
||||
#include "../../frontend/LevelFrontend.hpp"
|
||||
#include "../../items/Inventory.hpp"
|
||||
#include "../../items/ItemDef.hpp"
|
||||
#include "../../items/ItemStack.hpp"
|
||||
#include "../../files/files.hpp"
|
||||
#include "../../logic/PlayerController.hpp"
|
||||
#include "../../maths/FrustumCulling.hpp"
|
||||
#include "../../maths/voxmaths.hpp"
|
||||
@@ -70,6 +72,10 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
|
||||
settings.graphics.skyboxResolution.get(),
|
||||
assets->getShader("skybox_gen")
|
||||
);
|
||||
|
||||
auto name = "dingus.obj";
|
||||
auto text = files::read_string(fs::path(name));
|
||||
model = obj::parse(name, text);
|
||||
}
|
||||
|
||||
WorldRenderer::~WorldRenderer() {
|
||||
@@ -194,23 +200,13 @@ void WorldRenderer::renderLevel(
|
||||
|
||||
drawChunks(level->chunks.get(), camera, shader);
|
||||
|
||||
model::Model model {};
|
||||
auto& mesh = model.addMesh("gui/warning");
|
||||
mesh.addBox({}, glm::vec3(0.3f));
|
||||
mesh.addBox({}, glm::vec3(0.6f));
|
||||
|
||||
auto& mesh2 = model.addMesh("gui/error");
|
||||
mesh2.addBox({}, glm::vec3(0.7f));
|
||||
mesh2.addBox({}, glm::vec3(0.9f));
|
||||
|
||||
float timer = static_cast<float>(Window::time());
|
||||
assets->getTexture("gui/menubg")->bind();
|
||||
shader->uniformMatrix("u_model", glm::mat4(1.0f));
|
||||
modelBatch->translate({0, 86, 0});
|
||||
modelBatch->scale(glm::vec3(glm::sin(timer*6)+1));
|
||||
modelBatch->rotate(glm::vec3(1, 0, 0), timer);
|
||||
modelBatch->draw(model);
|
||||
modelBatch->popMatrix();
|
||||
modelBatch->translate({0, 85, 0});
|
||||
//modelBatch->scale(glm::vec3(glm::sin(timer*6)+10));
|
||||
modelBatch->rotate(glm::vec3(0, 1, 0), timer*6);
|
||||
modelBatch->draw(*model);
|
||||
//modelBatch->popMatrix();
|
||||
modelBatch->popMatrix();
|
||||
modelBatch->popMatrix();
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ class DrawContext;
|
||||
class ModelBatch;
|
||||
struct EngineSettings;
|
||||
|
||||
namespace model {
|
||||
struct Model;
|
||||
}
|
||||
|
||||
class WorldRenderer {
|
||||
Engine* engine;
|
||||
Level* level;
|
||||
@@ -36,6 +40,8 @@ class WorldRenderer {
|
||||
std::unique_ptr<Skybox> skybox;
|
||||
std::unique_ptr<Batch3D> batch3d;
|
||||
std::unique_ptr<ModelBatch> modelBatch;
|
||||
|
||||
std::unique_ptr<model::Model> model;
|
||||
bool drawChunk(size_t index, Camera* camera, Shader* shader, bool culling);
|
||||
void drawChunks(Chunks* chunks, Camera* camera, Shader* shader);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user