mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
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:
@@ -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;
|
||||
|
||||
BIN
resources/objects/backpack/ao.jpg
Normal file
BIN
resources/objects/backpack/ao.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
16
resources/objects/backpack/backpack.mtl
Normal file
16
resources/objects/backpack/backpack.mtl
Normal 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
|
||||
|
||||
199481
resources/objects/backpack/backpack.obj
Normal file
199481
resources/objects/backpack/backpack.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
resources/objects/backpack/diffuse.jpg
Normal file
BIN
resources/objects/backpack/diffuse.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.8 MiB |
BIN
resources/objects/backpack/normal.png
Normal file
BIN
resources/objects/backpack/normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 MiB |
BIN
resources/objects/backpack/roughness.jpg
Normal file
BIN
resources/objects/backpack/roughness.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 MiB |
3
resources/objects/backpack/source_attribution.txt
Normal file
3
resources/objects/backpack/source_attribution.txt
Normal 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.
|
||||
BIN
resources/objects/backpack/specular.jpg
Normal file
BIN
resources/objects/backpack/specular.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 MiB |
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user