diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 7eb6adfe..e41f52fb 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -2743,7 +2743,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) { } byte* newPalette = (byte*)(textures + texOffset + newOffset[3] + newWidths[3] * newHeights[3]); - float srcScale = (float)oldWidth / tex.nWidth; + float srcScaleX = (float)oldWidth / tex.nWidth; + float srcScaleY = (float)oldHeight / tex.nHeight; for (int i = 0; i < 4; i++) { byte* srcData = (byte*)(textures + texOffset + tex.nOffsets[i]); @@ -2752,10 +2753,10 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) { int dstWidth = newWidths[i]; for (int y = 0; y < newHeights[i]; y++) { - int srcY = (int)(srcScale * y + 0.5f); + int srcY = (int)(srcScaleY * y + 0.5f); for (int x = 0; x < newWidths[i]; x++) { - int srcX = (int)(srcScale * x + 0.5f); + int srcX = (int)(srcScaleX * x + 0.5f); dstData[y * dstWidth + x] = srcData[srcY * srcWidth + srcX]; } @@ -2769,7 +2770,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) { } // scale up face texture coordinates - float scale = tex.nWidth / (float)oldWidth; + float scaleX = tex.nWidth / (float)oldWidth; + float scaleY = tex.nHeight / (float)oldHeight; for (int i = 0; i < faceCount; i++) { BSPFACE& face = faces[i]; @@ -2792,8 +2794,8 @@ bool Bsp::downscale_texture(int textureId, int newWidth, int newHeight) { vec3 oldvs = info->vS; vec3 oldvt = info->vT; - info->vS *= scale; - info->vT *= scale; + info->vS *= scaleX; + info->vT *= scaleY; // get before/after uv coordinates float oldu = (dotProduct(oldvs, vert) + info->shiftS) * (1.0f / (float)oldWidth); @@ -2840,18 +2842,27 @@ bool Bsp::downscale_texture(int textureId, int maxDim) { int newWidth = tex.nWidth; int newHeight = tex.nHeight; - float ratio = oldHeight / (float)oldWidth; - - while (newWidth > 0 && (newWidth > maxDim || newHeight > maxDim || (newHeight % 16) != 0)) { - newWidth -= 16; - newHeight = newWidth * ratio; + if (tex.nWidth > maxDim && tex.nWidth > tex.nHeight) { + float ratio = oldHeight / (float)oldWidth; + newWidth = maxDim; + newHeight = (int)(((newWidth * ratio) + 8) / 16) * 16; + if (newHeight > oldHeight) { + newHeight = (int)((newWidth * ratio) / 16) * 16; + } } - - if (oldWidth == newWidth) { - return false; + else if (tex.nHeight > maxDim) { + float ratio = oldWidth / (float)oldHeight; + newHeight = maxDim; + newWidth = (int)(((newHeight * ratio) + 8) / 16) * 16; + if (newWidth > oldWidth) { + newWidth = (int)((newHeight * ratio) / 16) * 16; + } + } + else { + return false; // no need to downscale } - if (tex.nWidth == 0) { + if (oldWidth == newWidth && oldHeight == newHeight) { logf("Failed to downscale texture %s %dx%d to max dim %d\n", tex.szName, oldWidth, oldHeight, maxDim); return false; } diff --git a/src/editor/BspRenderer.cpp b/src/editor/BspRenderer.cpp index 1dcf66bb..0db612a1 100644 --- a/src/editor/BspRenderer.cpp +++ b/src/editor/BspRenderer.cpp @@ -1502,7 +1502,7 @@ void BspRenderer::render(int highlightEnt, bool highlightAlwaysOnTop, int clipno drawModelClipnodes(0, false, clipnodeHull); } - if (g_render_flags & RENDER_ENT_CLIPNODES) { + if ((g_render_flags & RENDER_ENTS) && (g_render_flags & RENDER_ENT_CLIPNODES)) { for (int i = 0, sz = map->ents.size(); i < sz; i++) { if (renderEnts[i].modelIdx >= 0 && renderEnts[i].modelIdx < map->modelCount) { if (clipnodeHull == -1 && renderModels[renderEnts[i].modelIdx].groupCount > 0) { diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 2b587be9..a27ba0f0 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -522,7 +522,7 @@ void Gui::draw3dContextMenus() { set downscaled; for (int i = 0; i < app->selectedFaces.size(); i++) { - BSPFACE& face = map->faces[app->pickInfo.faceIdx]; + BSPFACE& face = map->faces[app->selectedFaces[i]]; BSPTEXTUREINFO& info = map->texinfos[face.iTextureInfo]; if (downscaled.count(info.iMiptex)) @@ -541,8 +541,8 @@ void Gui::draw3dContextMenus() { else if (maxDim > 32) { nextBestDim = 32; } else if (maxDim > 32) { nextBestDim = 32; } - map->downscale_texture(info.iMiptex, nextBestDim); downscaled.insert(info.iMiptex); + map->downscale_texture(info.iMiptex, nextBestDim); } app->deselectFaces(); @@ -958,8 +958,12 @@ void Gui::drawMenuBar() { tooltip(g, "Render point-sized entities which either have no model or reference MDL/SPR files."); if (ImGui::MenuItem("Solid Entities", 0, g_render_flags & RENDER_ENTS)) { - g_render_flags ^= RENDER_ENTS; - g_render_flags |= RENDER_SPECIAL_ENTS; + if (g_render_flags & RENDER_ENTS) { + g_render_flags &= ~(RENDER_ENTS | RENDER_SPECIAL_ENTS); + } + else { + g_render_flags |= RENDER_ENTS | RENDER_SPECIAL_ENTS; + } } tooltip(g, "Render entities that reference BSP models."); @@ -1312,7 +1316,7 @@ void Gui::drawMenuBar() { } tooltip(g, "Subdivides faces until they have valid extents. The drawback to this method is reduced in-game performace from higher poly counts."); - ImGui::MenuItem("", "WIP"); + ImGui::MenuItem("##", "WIP"); tooltip(g, "Anything you choose here will break lightmaps. " "Run the map through a RAD compiler to fix, and pray that the mapper didn't " "customize compile settings much."); @@ -1496,11 +1500,15 @@ void Gui::drawToolbar() { if (app->pickInfo.valid && app->pickInfo.modelIdx >= 0) { Bsp* map = app->pickInfo.map; BspRenderer* mapRenderer = app->mapRenderers[app->pickInfo.mapIdx]; - BSPMODEL& model = map->models[app->pickInfo.modelIdx]; - for (int i = 0; i < model.nFaces; i++) { - int faceIdx = model.iFirstFace + i; - mapRenderer->highlightFace(faceIdx, true); - app->selectedFaces.push_back(faceIdx); + + // don't select all worldspawn faces because it lags the program + if (app->pickInfo.modelIdx != 0) { + BSPMODEL& model = map->models[app->pickInfo.modelIdx]; + for (int i = 0; i < model.nFaces; i++) { + int faceIdx = model.iFirstFace + i; + mapRenderer->highlightFace(faceIdx, true); + app->selectedFaces.push_back(faceIdx); + } } } app->selectMapIdx = app->pickInfo.mapIdx; @@ -1688,7 +1696,7 @@ void Gui::drawDebugWidget() { } - if (app->pickInfo.valid) { + if (app->pickInfo.valid && app->pickInfo.map) { Bsp* map = app->pickInfo.map; if (ImGui::CollapsingHeader("Map", ImGuiTreeNodeFlags_DefaultOpen)) diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index abef68a5..2cc13ecf 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -1682,7 +1682,7 @@ void Renderer::drawPlane(BSPPLANE& plane, COLOR4 color) { vec3 right = crossProduct(plane.vNormal, crossDir); vec3 up = crossProduct(right, plane.vNormal); - float s = 100.0f; + float s = 32768.0f; vec3 topLeft = vec3(ori + right * -s + up * s).flip(); vec3 topRight = vec3(ori + right * s + up * s).flip();