Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d18d4d9

Browse files
committed
Update tutorial to match latest API of tinyobjloader
1 parent 948ff26 commit d18d4d9

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

08_Loading_models.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ We will use the [tinyobjloader](https://github.com/syoyo/tinyobjloader) library
1818
to load vertices and faces from an OBJ file. It's fast and it's easy to
1919
integrate because it's a single file library like stb_image. Go to the
2020
repository linked above and download the `tiny_obj_loader.h` file to a folder in
21-
your library directory.
21+
your library directory. Make sure to use the version of the file from the `master` branch because the latest official release is outdated.
2222

2323
**Visual Studio**
2424

@@ -139,10 +139,10 @@ void loadModel() {
139139
tinyobj::attrib_t attrib;
140140
std::vector<tinyobj::shape_t> shapes;
141141
std::vector<tinyobj::material_t> materials;
142-
std::string err;
142+
std::string warn, err;
143143

144-
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, MODEL_PATH.c_str())) {
145-
throw std::runtime_error(err);
144+
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, MODEL_PATH.c_str())) {
145+
throw std::runtime_error(warn + err);
146146
}
147147
}
148148
```
@@ -159,7 +159,7 @@ faces. Each face consists of an array of vertices, and each vertex contains the
159159
indices of the position, normal and texture coordinate attributes. OBJ models
160160
can also define a material and texture per face, but we will be ignoring those.
161161

162-
The `err` string contains errors and warnings that occurred while loading the
162+
The `err` string contains errors and the `warn` string contains warnings that occurred while loading the
163163
file, like a missing material definition. Loading only really failed if the
164164
`LoadObj` function returns `false`. As mentioned above, faces in OBJ files can
165165
actually contain an arbitrary number of vertices, whereas our application can

code/27_model_loading.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,10 @@ class HelloTriangleApplication {
10031003
tinyobj::attrib_t attrib;
10041004
std::vector<tinyobj::shape_t> shapes;
10051005
std::vector<tinyobj::material_t> materials;
1006-
std::string err;
1006+
std::string warn, err;
10071007

1008-
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, MODEL_PATH.c_str())) {
1009-
throw std::runtime_error(err);
1008+
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, MODEL_PATH.c_str())) {
1009+
throw std::runtime_error(warn + err);
10101010
}
10111011

10121012
std::unordered_map<Vertex, uint32_t> uniqueVertices = {};

code/28_mipmapping.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,10 @@ class HelloTriangleApplication {
10971097
tinyobj::attrib_t attrib;
10981098
std::vector<tinyobj::shape_t> shapes;
10991099
std::vector<tinyobj::material_t> materials;
1100-
std::string err;
1100+
std::string warn, err;
11011101

1102-
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, MODEL_PATH.c_str())) {
1103-
throw std::runtime_error(err);
1102+
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, MODEL_PATH.c_str())) {
1103+
throw std::runtime_error(warn + err);
11041104
}
11051105

11061106
std::unordered_map<Vertex, uint32_t> uniqueVertices = {};

code/29_multisampling.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,10 @@ VkSampleCountFlagBits getMaxUsableSampleCount() {
11561156
tinyobj::attrib_t attrib;
11571157
std::vector<tinyobj::shape_t> shapes;
11581158
std::vector<tinyobj::material_t> materials;
1159-
std::string err;
1159+
std::string warn, err;
11601160

1161-
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &err, MODEL_PATH.c_str())) {
1162-
throw std::runtime_error(err);
1161+
if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, MODEL_PATH.c_str())) {
1162+
throw std::runtime_error(warn + err);
11631163
}
11641164

11651165
std::unordered_map<Vertex, uint32_t> uniqueVertices = {};

0 commit comments

Comments
 (0)