@@ -1518,13 +1518,13 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
1518
1518
StackVector<std::thread, 16 > workers;
1519
1519
1520
1520
for (size_t t = 0 ; t < num_threads; t++) {
1521
- int material_id = -1 ; // -1 = default unknown material.
1522
1521
workers->push_back (std::thread ([&, t]() {
1523
1522
size_t v_count = v_offsets[t];
1524
1523
size_t n_count = n_offsets[t];
1525
1524
size_t t_count = t_offsets[t];
1526
1525
size_t f_count = f_offsets[t];
1527
1526
size_t face_count = face_offsets[t];
1527
+ int material_id = -1 ; // -1 = default unknown material.
1528
1528
1529
1529
for (size_t i = 0 ; i < commands[t].size (); i++) {
1530
1530
if (commands[t][i].type == COMMAND_EMPTY) {
@@ -1581,7 +1581,19 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes,
1581
1581
for (size_t t = 0 ; t < workers->size (); t++) {
1582
1582
workers[t].join ();
1583
1583
}
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
+ }
1585
1597
auto t_end = std::chrono::high_resolution_clock::now ();
1586
1598
ms_merge = t_end - t_start;
1587
1599
}
0 commit comments