Update model chapter, and add new backpack model to repo (w/ attribution mention). Also use new model on deferred source code.

This commit is contained in:
Joey de Vries
2020-04-30 14:32:14 +02:00
parent f9ae66b16a
commit 66d51ae668
12 changed files with 199517 additions and 10 deletions

View File

@@ -26,13 +26,12 @@ unsigned int TextureFromFile(const char *path, const string &directory, bool gam
class Model
{
public:
/* Model Data */
// model data
vector<Texture> textures_loaded; // stores all the textures loaded so far, optimization to make sure textures aren't loaded more than once.
vector<Mesh> meshes;
vector<Mesh> meshes;
string directory;
bool gammaCorrection;
/* Functions */
// constructor, expects a filepath to a 3D model.
Model(string const &path, bool gamma = false) : gammaCorrection(gamma)
{
@@ -47,7 +46,6 @@ public:
}
private:
/* Functions */
// loads a model with supported ASSIMP extensions from file and stores the resulting meshes in the meshes vector.
void loadModel(string const &path)
{
@@ -93,7 +91,7 @@ private:
vector<unsigned int> indices;
vector<Texture> textures;
// Walk through each of the mesh's vertices
// walk through each of the mesh's vertices
for(unsigned int i = 0; i < mesh->mNumVertices; i++)
{
Vertex vertex;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

View File

@@ -0,0 +1,16 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl Scene_-_Root
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.450000
d 1.000000
illum 2
map_Kd diffuse.jpg
map_Bump normal.png
map_Ks specular.jpg

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

View File

@@ -0,0 +1,3 @@
Model by Berk Gedik, from: https://sketchfab.com/3d-models/survival-guitar-backpack-low-poly-799f8c4511f84fab8c3f12887f7e6b36
Modified material assignment (Joey de Vries) for easier load in OpenGL model loading chapter, and renamed albedo to diffuse and metallic to specular to match non-PBR lighting setup.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

View File

@@ -69,6 +69,9 @@ int main()
return -1;
}
// tell stb_image.h to flip loaded texture's on the y-axis (before loading model).
stbi_set_flip_vertically_on_load(true);
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
@@ -79,7 +82,7 @@ int main()
// load models
// -----------
Model ourModel(FileSystem::getPath("resources/objects/nanosuit/nanosuit.obj"));
Model ourModel(FileSystem::getPath("resources/objects/backpack/backpack.obj"));
// draw in wireframe
@@ -115,8 +118,8 @@ int main()
// render the loaded model
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(0.0f, -1.75f, 0.0f)); // translate it down so it's at the center of the scene
model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f)); // it's a bit too big for our scene, so scale it down
model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f)); // translate it down so it's at the center of the scene
model = glm::scale(model, glm::vec3(1.0f, 1.0f, 1.0f)); // it's a bit too big for our scene, so scale it down
ourShader.setMat4("model", model);
ourModel.Draw(ourShader);

View File

@@ -72,6 +72,9 @@ int main()
return -1;
}
// tell stb_image.h to flip loaded texture's on the y-axis (before loading model).
stbi_set_flip_vertically_on_load(true);
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
@@ -84,7 +87,7 @@ int main()
// load models
// -----------
Model nanosuit(FileSystem::getPath("resources/objects/nanosuit/nanosuit.obj"));
Model nanosuit(FileSystem::getPath("resources/objects/backpack/backpack.obj"));
std::vector<glm::vec3> objectPositions;
objectPositions.push_back(glm::vec3(-3.0, -3.0, -3.0));
objectPositions.push_back(glm::vec3( 0.0, -3.0, -3.0));

View File

@@ -72,6 +72,9 @@ int main()
return -1;
}
// tell stb_image.h to flip loaded texture's on the y-axis (before loading model).
stbi_set_flip_vertically_on_load(true);
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
@@ -84,7 +87,7 @@ int main()
// load models
// -----------
Model nanosuit(FileSystem::getPath("resources/objects/nanosuit/nanosuit.obj"));
Model nanosuit(FileSystem::getPath("resources/objects/backpack/backpack.obj"));
std::vector<glm::vec3> objectPositions;
objectPositions.push_back(glm::vec3(-3.0, -3.0, -3.0));
objectPositions.push_back(glm::vec3( 0.0, -3.0, -3.0));