Update callback API example.

Update API document.
This commit is contained in:
Syoyo Fujita
2016-07-28 16:21:48 +09:00
parent dfe9d7bcae
commit 1983e889dc
2 changed files with 6 additions and 7 deletions

View File

@@ -62,7 +62,7 @@ void index_cb(void *user_data, tinyobj::index_t *indices, int num_indices) {
// index). // index).
// Also, the first index starts with 1, not 0. // Also, the first index starts with 1, not 0.
// See fixIndex() function in tiny_obj_loader.h for details. // See fixIndex() function in tiny_obj_loader.h for details.
// Also, -2147483648(0x80000000 = -INT_MAX) is set for the index value which // Also, 0 is set for the index value which
// does not exist in .obj // does not exist in .obj
MyMesh *mesh = reinterpret_cast<MyMesh *>(user_data); MyMesh *mesh = reinterpret_cast<MyMesh *>(user_data);
@@ -71,13 +71,13 @@ void index_cb(void *user_data, tinyobj::index_t *indices, int num_indices) {
printf("idx[%ld] = %d, %d, %d\n", mesh->v_indices.size(), idx.vertex_index, printf("idx[%ld] = %d, %d, %d\n", mesh->v_indices.size(), idx.vertex_index,
idx.normal_index, idx.texcoord_index); idx.normal_index, idx.texcoord_index);
if (idx.vertex_index != 0x80000000) { if (idx.vertex_index != 0) {
mesh->v_indices.push_back(idx.vertex_index); mesh->v_indices.push_back(idx.vertex_index);
} }
if (idx.normal_index != 0x80000000) { if (idx.normal_index != 0) {
mesh->vn_indices.push_back(idx.normal_index); mesh->vn_indices.push_back(idx.normal_index);
} }
if (idx.texcoord_index != 0x80000000) { if (idx.texcoord_index != 0) {
mesh->vt_indices.push_back(idx.texcoord_index); mesh->vt_indices.push_back(idx.texcoord_index);
} }
} }
@@ -143,7 +143,7 @@ int main(int argc, char **argv) {
tinyobj::MaterialFileReader mtlReader("../../models/"); tinyobj::MaterialFileReader mtlReader("../../models/");
bool ret = tinyobj::LoadObjWithCallback(&mesh, cb, &err, &ifs, &mtlReader); bool ret = tinyobj::LoadObjWithCallback(ifs, cb, &mesh, &mtlReader, &err);
if (!err.empty()) { if (!err.empty()) {
std::cerr << err << std::endl; std::cerr << err << std::endl;

View File

@@ -156,8 +156,7 @@ typedef struct callback_t_ {
// called per 'f' line. num_indices is the number of face indices(e.g. 3 for // called per 'f' line. num_indices is the number of face indices(e.g. 3 for
// triangle, 4 for quad) // triangle, 4 for quad)
// -2147483648(-INT_MAX) will be passed for undefined index in index_t // 0 will be passed for undefined index in index_t members.
// members.
void (*index_cb)(void *user_data, index_t *indices, int num_indices); void (*index_cb)(void *user_data, index_t *indices, int num_indices);
// `name` material name, `material_id` = the array index of material_t[]. -1 // `name` material name, `material_id` = the array index of material_t[]. -1
// if // if