diff --git a/common/bspinfo.cc b/common/bspinfo.cc index df5d07ad..bbdf14cf 100644 --- a/common/bspinfo.cc +++ b/common/bspinfo.cc @@ -373,6 +373,54 @@ static json generate_lightmap_atlases(const mbsp_t &bsp, const bspxentries_t &bs memset(full_atlas.pixels.data(), 0, sizeof(*full_atlas.pixels.data()) * full_atlas.pixels.size()); } + auto ExportObjFace = [&full_atlas](std::iostream &f, const mbsp_t *bsp, const face_rect &face, int &vertcount) + { + // export the vertices and uvs + for (int i = 0; i < face.face->numedges; i++) { + const int vertnum = Face_VertexAtIndex(bsp, face.face, i); + const qvec3f normal = bsp->dplanes[face.face->planenum].normal; + const qvec3f &pos = bsp->dvertexes[vertnum]; + fmt::print(f, "v {:.9} {:.9} {:.9}\n", pos[0], pos[1], pos[2]); + fmt::print(f, "vn {:.9} {:.9} {:.9}\n", normal[0], normal[1], normal[2]); + + auto tc = face.extents.worldToLMCoord(pos); + tc[0] += face.x; + tc[1] += face.y; + + tc[0] /= full_atlas.width; + tc[1] /= full_atlas.height; + + tc[1] = 1.0 - tc[1]; + + fmt::print(f, "vt {:.9} {:.9}\n", tc[0], tc[1]); + } + + f << "f"; + for (int i = 0; i < face.face->numedges; i++) { + // .obj vertexes start from 1 + // .obj faces are CCW, quake is CW, so reverse the order + const int vertindex = vertcount + (face.face->numedges - 1 - i) + 1; + fmt::print(f, " {0}/{0}/{0}", vertindex); + } + f << '\n'; + + vertcount += face.face->numedges; + }; + + auto ExportObj = [&ExportObjFace, &rectangles](const mbsp_t *bsp) + { + std::stringstream objfile; + int vertcount = 0; + + for (auto &rect : rectangles) { + ExportObjFace(objfile, bsp, rect, vertcount); + } + + return objfile.str(); + }; + + obj.emplace("obj", ExportObj(&bsp)); + return obj; } diff --git a/include/common/bsputils.hh b/include/common/bsputils.hh index c2dd69d1..8b64411b 100644 --- a/include/common/bsputils.hh +++ b/include/common/bsputils.hh @@ -221,7 +221,7 @@ public: qvec3d radius = (bounds.maxs() - bounds.mins()) * 0.5; origin = bounds.mins() + radius; - radius = qv::length(radius); + this->radius = qv::length(radius); } constexpr int width() const diff --git a/light/bounce.cc b/light/bounce.cc index 37d31628..3bfda5c5 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -169,7 +169,7 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m return; } - const vec_t sample_scalar = 1.f / sqrt(area) / (options.extra.value() * options.extra.value()); + const vec_t sample_scalar = 1.f / sqrt(area) / (options.extra.value() * options.extra.value()) * (surf.lightmapscale / 16.0); qplane3d faceplane = winding.plane();