Fix dragon UV's to allow it to run without crashing

This commit is contained in:
Lillian Salehi 2024-10-16 22:23:21 -05:00
parent 57496aea2c
commit 6e8e75d5b3
5 changed files with 11 additions and 8 deletions

Binary file not shown.

After

(image error) Size: 1.0 MiB

View File

@ -44,8 +44,8 @@ namespace Global {
extern VkImageView depthImageView; extern VkImageView depthImageView;
extern VkImage depthImage; extern VkImage depthImage;
extern VkDeviceMemory depthImageMemory; extern VkDeviceMemory depthImageMemory;
const std::string MODEL_PATH = "assets/models/viking_room.obj"; const std::string MODEL_PATH = "assets/models/StanfordDragon800k.obj";
const std::string TEXTURE_PATH = "assets/textures/viking_room.png"; const std::string TEXTURE_PATH = "assets/textures/checkermap.png";
@ -95,7 +95,7 @@ namespace Global {
}; };
const uint32_t WIDTH = 800; const uint32_t WIDTH = 800;
const uint32_t HEIGHT = 800; const uint32_t HEIGHT = 600;
extern std::vector<Vertex> vertices; extern std::vector<Vertex> vertices;
// Index buffer definition, showing which points to reuse. // Index buffer definition, showing which points to reuse.
extern std::vector<uint32_t> indices; extern std::vector<uint32_t> indices;

View File

@ -203,7 +203,7 @@ namespace buffers_libs {
ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(30.0f), glm::vec3(0.0f, 0.0f, 1.0f)); ubo.model = glm::rotate(glm::mat4(1.0f), time * glm::radians(30.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// Modify the view transformation to look at the object from above at a 45 degree angle. // Modify the view transformation to look at the object from above at a 45 degree angle.
// This takes the eye position, center position, and the up direction. // This takes the eye position, center position, and the up direction.
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)); ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 3.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// 45 degree field of view, set aspect ratio, and near and far clipping range. // 45 degree field of view, set aspect ratio, and near and far clipping range.
ubo.proj = glm::perspective(glm::radians(45.0f), device_libs::DeviceControl::getSwapChainExtent().width / (float) device_libs::DeviceControl::getSwapChainExtent().height, 0.1f, 10.0f); ubo.proj = glm::perspective(glm::radians(45.0f), device_libs::DeviceControl::getSwapChainExtent().width / (float) device_libs::DeviceControl::getSwapChainExtent().height, 0.1f, 10.0f);

View File

@ -94,7 +94,7 @@ namespace graphics_pipeline {
rasterizer.polygonMode = VK_POLYGON_MODE_FILL; rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
rasterizer.lineWidth = 1.0f; rasterizer.lineWidth = 1.0f;
// How to cull the faces, right here we cull the back faces and tell the rasterizer front facing vertices are ordered clockwise. // How to cull the faces, right here we cull the back faces and tell the rasterizer front facing vertices are ordered clockwise.
rasterizer.cullMode = VK_CULL_MODE_BACK_BIT; rasterizer.cullMode = VK_CULL_MODE_NONE;
rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
// Whether or not to add depth values. e.x. for shadow maps. // Whether or not to add depth values. e.x. for shadow maps.
rasterizer.depthBiasEnable = VK_FALSE; rasterizer.depthBiasEnable = VK_FALSE;

View File

@ -16,7 +16,7 @@ namespace modellib {
void Model::loadModel() { void Model::loadModel() {
tinyobj::ObjReaderConfig readerConfig; tinyobj::ObjReaderConfig readerConfig;
tinyobj::ObjReader reader; tinyobj::ObjReader reader;
if(!reader.ParseFromFile(Global::MODEL_PATH, readerConfig)) { if(!reader.ParseFromFile(Global::MODEL_PATH, readerConfig)) {
@ -30,7 +30,7 @@ namespace modellib {
auto& attrib = reader.GetAttrib(); auto& attrib = reader.GetAttrib();
auto& shapes = reader.GetShapes(); auto& shapes = reader.GetShapes();
//auto& materials = reader.GetMaterials(); auto& materials = reader.GetMaterials();
for (const auto& shape : shapes) { for (const auto& shape : shapes) {
for (const auto& index : shape.mesh.indices) { for (const auto& index : shape.mesh.indices) {
@ -42,7 +42,10 @@ namespace modellib {
attrib.vertices[3 * index.vertex_index + 2] attrib.vertices[3 * index.vertex_index + 2]
}; };
//TODO: Major fix here, running anything but the viking room OBJ crashes on texcoord assignment! //TODO: Small fix here, handle if there are no UV's unwrapped for the model.
// As of now, if it is not unwrapped, it segfaults on texCoord assignment.
// Obviously we should always have UV's, but it shouldn't crash, just unwrap
// in a default method.
vertex.texCoord = { vertex.texCoord = {
attrib.texcoords[2 * index.texcoord_index + 0], attrib.texcoords[2 * index.texcoord_index + 0],
1.0f - attrib.texcoords[2 * index.texcoord_index + 1] 1.0f - attrib.texcoords[2 * index.texcoord_index + 1]