Calculate normals if there aren't any, texture store file path
This commit is contained in:
parent
ab09107d23
commit
e0049c61ba
|
@ -63,19 +63,19 @@ namespace simpleengine {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) {
|
||||||
rotation.z += camera_speed;
|
rotation.z += camera_speed * .3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
|
||||||
rotation.z -= camera_speed;
|
rotation.z -= camera_speed * .3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) {
|
||||||
rotation.y -= camera_speed;
|
rotation.y -= camera_speed * .3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) {
|
||||||
rotation.y += camera_speed;
|
rotation.y += camera_speed * .3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the pitch of the camera.
|
// Limit the pitch of the camera.
|
||||||
|
|
|
@ -73,8 +73,10 @@ namespace simpleengine::gfx {
|
||||||
simpleengine::Vectorf position(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
simpleengine::Vectorf position(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||||
vertex.position = position;
|
vertex.position = position;
|
||||||
|
|
||||||
glm::vec3 normal(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
if (mesh->HasNormals()) {
|
||||||
vertex.normal = normal;
|
glm::vec3 normal(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
||||||
|
vertex.normal = normal;
|
||||||
|
}
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0]) {
|
if (mesh->mTextureCoords[0]) {
|
||||||
glm::vec2 tex_coord(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y);
|
glm::vec2 tex_coord(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y);
|
||||||
|
@ -142,7 +144,13 @@ namespace simpleengine::gfx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Mesh(vertices, indices, mat);
|
Mesh se_mesh(vertices, indices, mat);
|
||||||
|
|
||||||
|
if (!mesh->HasNormals()) {
|
||||||
|
se_mesh.calculate_normals();
|
||||||
|
}
|
||||||
|
|
||||||
|
return se_mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<aiTextureType, std::vector<Texture>> load_all_textures(aiMaterial* material) {
|
std::unordered_map<aiTextureType, std::vector<Texture>> load_all_textures(aiMaterial* material) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
namespace simpleengine::gfx {
|
namespace simpleengine::gfx {
|
||||||
Texture::Texture(const char* path, aiTextureType type, int flags): type(type) {
|
Texture::Texture(const char* path, aiTextureType type, int flags): type(type), path(path) {
|
||||||
bool img_2d = flags & TextureFlags::TexFlags_IMG_2D;
|
bool img_2d = flags & TextureFlags::TexFlags_IMG_2D;
|
||||||
bool flip_vertically = flags & TextureFlags::TexFlags_FLIP_VERTICALLY;
|
bool flip_vertically = flags & TextureFlags::TexFlags_FLIP_VERTICALLY;
|
||||||
bool mipmap = flags & TextureFlags::TexFlags_MIPMAP;
|
bool mipmap = flags & TextureFlags::TexFlags_MIPMAP;
|
||||||
|
@ -23,7 +23,7 @@ namespace simpleengine::gfx {
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(flip_vertically);
|
stbi_set_flip_vertically_on_load(flip_vertically);
|
||||||
|
|
||||||
// Read 4 channels (RGBA)
|
// Read 4 channels (RGBA)
|
||||||
img_data = stbi_load(path, &width, &height, &channels, 4);
|
img_data = stbi_load(path, &width, &height, &channels, 4);
|
||||||
if(!img_data) {
|
if(!img_data) {
|
||||||
const char* failure = stbi_failure_reason();
|
const char* failure = stbi_failure_reason();
|
||||||
|
|
Loading…
Reference in New Issue