From 5bdeae8dad38885bdcc29ee7ba511c49790b08e8 Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Wed, 12 Oct 2022 23:06:49 +0200 Subject: [PATCH] Add warning if normal or tangents are missing --- src/Camera.cpp | 2 +- src/Controller.cpp | 4 ++-- src/VertexArray.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Camera.cpp b/src/Camera.cpp index 86b119b..7f54247 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -18,7 +18,7 @@ void Camera::updateVPM() void Camera::updateAspectRatio(float aspectRatio) { - m_projectionMatrix = glm::perspective(m_fov / 2.F, aspectRatio, .1F, 1000.F); + m_projectionMatrix = glm::perspective(m_fov / 2.F, aspectRatio, .01F, 1000.F); updateVPM(); } diff --git a/src/Controller.cpp b/src/Controller.cpp index 5d2b911..f7cdd85 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -26,11 +26,11 @@ Controller::Controller() std::string err; std::string warn; - bool ret = loader.LoadASCIIFromFile(&m_model, &err, &warn, "WaterBottle/glTF/WaterBottle.gltf"); + // bool ret = loader.LoadASCIIFromFile(&m_model, &err, &warn, "WaterBottle/glTF/WaterBottle.gltf"); // bool ret = loader.LoadASCIIFromFile(&m_model, &err, &warn, "Duck/glTF/Duck.gltf"); // bool ret = loader.LoadASCIIFromFile(&m_model, &err, &warn, "Lantern/glTF/Lantern.gltf"); // bool ret = loader.LoadBinaryFromFile(&m_model, &err, &warn, "Camera.glb"); - // bool ret = loader.LoadBinaryFromFile(&m_model, &err, &warn, "ABeautifulGame/ABeautifulGame.glb"); + bool ret = loader.LoadBinaryFromFile(&m_model, &err, &warn, "ABeautifulGame/ABeautifulGame.glb"); if (!warn.empty()) { Log::logger().warn("{}", warn); diff --git a/src/VertexArray.cpp b/src/VertexArray.cpp index db93980..6465e39 100644 --- a/src/VertexArray.cpp +++ b/src/VertexArray.cpp @@ -1,5 +1,6 @@ #include "VertexArray.h" #include "definitions/models.h" +#include "util/Log.h" #include #include @@ -11,12 +12,18 @@ VertexArray::VertexArray(tinygltf::Primitive const &primitive, tinygltf::Model c glGenVertexArrays(1, &vao); glBindVertexArray(vao); + if (!primitive.attributes.contains("TANGENT") || !primitive.attributes.contains("NORMAL")) { + Log::logger().critical("glTF scene has to include tangent and normal components!"); + exit(-1); + } + int position_accessor_id = primitive.attributes.at("POSITION"); int normal_accessor_id = primitive.attributes.at("NORMAL"); int uv_accessor_id = primitive.attributes.at("TEXCOORD_0"); int tangent_accessor_id = primitive.attributes.at("TANGENT"); int indices_accessor_id = primitive.indices; + auto const &position_accessor = model.accessors.at(position_accessor_id); auto const &normal_accessor = model.accessors.at(normal_accessor_id); auto const &uv_accessor = model.accessors.at(uv_accessor_id); @@ -126,8 +133,8 @@ VertexArray::VertexArray(tinygltf::Primitive const &primitive, tinygltf::Model c { glGenBuffers(1, &tangentVbo); glBindBuffer(GL_ARRAY_BUFFER, tangentVbo); - glBufferData(GL_ARRAY_BUFFER, tangent_buffer_view.byteLength, tangent_buffer.data.data() + tangent_buffer_view.byteOffset, - GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, tangent_buffer_view.byteLength, + tangent_buffer.data.data() + tangent_buffer_view.byteOffset, GL_STATIC_DRAW); int size = 1; if (tangent_accessor.type == TINYGLTF_TYPE_SCALAR) {