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

Skip to content

Commit cb085d1

Browse files
committed
fix multiple texture wrong id problem
1 parent b38e97b commit cb085d1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

experimental/tinyobj_loader_opt.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,13 +1518,13 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
15181518
StackVector<std::thread, 16> workers;
15191519

15201520
for (size_t t = 0; t < num_threads; t++) {
1521-
int material_id = -1; // -1 = default unknown material.
15221521
workers->push_back(std::thread([&, t]() {
15231522
size_t v_count = v_offsets[t];
15241523
size_t n_count = n_offsets[t];
15251524
size_t t_count = t_offsets[t];
15261525
size_t f_count = f_offsets[t];
15271526
size_t face_count = face_offsets[t];
1527+
int material_id = -1; // -1 = default unknown material.
15281528

15291529
for (size_t i = 0; i < commands[t].size(); i++) {
15301530
if (commands[t][i].type == COMMAND_EMPTY) {
@@ -1581,7 +1581,19 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
15811581
for (size_t t = 0; t < workers->size(); t++) {
15821582
workers[t].join();
15831583
}
1584-
1584+
if(material_map.size()>1&& num_threads>1) {
1585+
for (size_t t = 0; t < num_threads; t++) {
1586+
size_t face_count = face_offsets[t];
1587+
if (-1 == attrib->material_ids[face_count]) {
1588+
int prev_material_id = attrib->material_ids[face_count - 1];
1589+
size_t max_face_offset = (t == num_threads - 1) ? attrib->material_ids.size() : face_offsets[t + 1];
1590+
for (int i = face_count; i<max_face_offset; ++i) {
1591+
if (attrib->material_ids[i] != -1) break;
1592+
attrib->material_ids[i] = prev_material_id;
1593+
}
1594+
}
1595+
}
1596+
}
15851597
auto t_end = std::chrono::high_resolution_clock::now();
15861598
ms_merge = t_end - t_start;
15871599
}

0 commit comments

Comments
 (0)