Skip to content

Commit 68aafbe

Browse files
committed
bspinfo: ExportObjFace: handle atlas.facenum_to_lightmap_uvs not containing all faces
fixes many test failures
1 parent da97f68 commit 68aafbe

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

common/bspinfo.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
628628
auto ExportObjFace = [&atlas](std::ostream &f, const mbsp_t *bsp, int face_num, int &vertcount) {
629629
const auto *face = BSP_GetFace(bsp, face_num);
630630

631-
const auto &tcs = atlas.facenum_to_lightmap_uvs.at(face_num);
631+
auto tcs_it = atlas.facenum_to_lightmap_uvs.find(face_num);
632632

633633
// export the vertices and uvs
634634
for (int i = 0; i < face->numedges; i++) {
@@ -638,11 +638,15 @@ static void export_obj_and_lightmaps(const mbsp_t &bsp, const bspxentries_t &bsp
638638
ewt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]);
639639
ewt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]);
640640

641-
qvec2f tc = tcs[i];
641+
if (tcs_it != atlas.facenum_to_lightmap_uvs.end()) {
642+
qvec2f tc = tcs_it->second[i];
642643

643-
tc[1] = 1.0 - tc[1];
644+
tc[1] = 1.0 - tc[1];
644645

645-
ewt::print(f, "vt {:.9} {:.9}\n", tc[0], tc[1]);
646+
ewt::print(f, "vt {:.9} {:.9}\n", tc[0], tc[1]);
647+
} else {
648+
ewt::print(f, "vt 0 0\n");
649+
}
646650
}
647651

648652
f << "f";

0 commit comments

Comments
 (0)