@@ -627,7 +627,7 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
627627 auto ExportObjFace = [&atlas](std::ostream &f, const mbsp_t *bsp, int face_num, int &vertcount) {
628628 const auto *face = BSP_GetFace (bsp, face_num);
629629
630- const auto &tcs = atlas.facenum_to_lightmap_uvs .at (face_num);
630+ auto tcs_it = atlas.facenum_to_lightmap_uvs .find (face_num);
631631
632632 // export the vertices and uvs
633633 for (int i = 0 ; i < face->numedges ; i++) {
@@ -637,11 +637,15 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
637637 ewt::print (f, " v {:.9} {:.9} {:.9}\n " , pos[0 ], pos[1 ], pos[2 ]);
638638 ewt::print (f, " vn {:.9} {:.9} {:.9}\n " , normal[0 ], normal[1 ], normal[2 ]);
639639
640- qvec2f tc = tcs[i];
640+ if (tcs_it != atlas.facenum_to_lightmap_uvs .end ()) {
641+ qvec2f tc = tcs_it->second [i];
641642
642- tc[1 ] = 1.0 - tc[1 ];
643+ tc[1 ] = 1.0 - tc[1 ];
643644
644- ewt::print (f, " vt {:.9} {:.9}\n " , tc[0 ], tc[1 ]);
645+ ewt::print (f, " vt {:.9} {:.9}\n " , tc[0 ], tc[1 ]);
646+ } else {
647+ ewt::print (f, " vt 0 0\n " );
648+ }
645649 }
646650
647651 f << " f" ;
0 commit comments