Skip to content

Commit

Permalink
First CSM export test
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Mar 22, 2024
1 parent 78cc84e commit 765ed55
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 115 deletions.
287 changes: 193 additions & 94 deletions src/bsp/Bsp.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bsp/Bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class Bsp

void ExportToSmdWIP(const std::string& path, bool split, bool oneRoot);

void ExportToObjWIP(const std::string& path, int iscale = 1, bool lightmap_mode = false, bool with_mdl = false);
void ExportToObjWIP(const std::string& path, int iscale = 1, bool lightmap_mode = false, bool with_mdl = false, bool export_csm = false);

void ExportToMapWIP(const std::string& path, bool selected, bool merge_faces, bool use_one_back_vert);

Expand Down
4 changes: 2 additions & 2 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ void BspRenderer::deleteFaceMaths()
faceMaths = NULL;
}

int BspRenderer::refreshModel(int modelIdx, bool refreshClipnodes, bool noTriangulate)
int BspRenderer::refreshModel(int modelIdx, bool refreshClipnodes, bool triangulate)
{
if (modelIdx < 0 || modelIdx >= map->modelCount)
return 0;
Expand Down Expand Up @@ -1127,7 +1127,7 @@ int BspRenderer::refreshModel(int modelIdx, bool refreshClipnodes, bool noTriang
}
}

if (!noTriangulate)
if (triangulate)
{
idx = 0;
// convert TRIANGLE_FAN verts to TRIANGLES so multiple faces can be drawn in a single draw call
Expand Down
2 changes: 1 addition & 1 deletion src/editor/BspRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class BspRenderer

bool setRenderAngles(const std::string& classname, mat4x4& outmat, vec3& outangles);
void refreshEnt(size_t entIdx);
int refreshModel(int modelIdx, bool refreshClipnodes = true, bool noTriangulate = false);
int refreshModel(int modelIdx, bool refreshClipnodes = true, bool triangulate = true);
bool refreshModelClipnodes(int modelIdx);
void refreshFace(int faceIdx);
void updateClipnodeOpacity(unsigned char newValue);
Expand Down
40 changes: 28 additions & 12 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ void Gui::drawBspContexMenu()
{
BSPFACE32 face = map->faces[f];

if (std::find(app->pickInfo.selectedFaces.begin(), app->pickInfo.selectedFaces.end(), f) != app->pickInfo.selectedFaces.end())
if (std::find(app->pickInfo.selectedFaces.begin(), app->pickInfo.selectedFaces.end(), (size_t)f) != app->pickInfo.selectedFaces.end())
{
continue;
}
Expand Down Expand Up @@ -2810,7 +2810,7 @@ void Gui::drawMenuBar()

static int g_scale = 1;

if (ImGui::BeginMenu("Wavefront (.obj) [WIP]", map && !map->is_mdl_model))
if (ImGui::BeginMenu("Wavefront(.obj)/XashNT(.csm) [WIP]", map && !map->is_mdl_model))
{

if (ImGui::BeginMenu("Select scale"))
Expand Down Expand Up @@ -2841,14 +2841,30 @@ void Gui::drawMenuBar()
ImGui::EndMenu();
}

if (ImGui::MenuItem("Export only bsp"))
if (ImGui::BeginMenu("Export only bsp"))
{
map->ExportToObjWIP(g_working_dir, g_scale);
if (ImGui::MenuItem("Export .obj"))
{
map->ExportToObjWIP(g_working_dir, g_scale);
}
if (ImGui::MenuItem("Export .csm"))
{
map->ExportToObjWIP(g_working_dir, g_scale, false, false, true);
}
ImGui::EndMenu();
}

if (ImGui::MenuItem("Export with models"))
if (ImGui::BeginMenu("Export with models"))
{
map->ExportToObjWIP(g_working_dir, g_scale, false, true);
if (ImGui::MenuItem("Export .obj"))
{
map->ExportToObjWIP(g_working_dir, g_scale, false, true);
}
if (ImGui::MenuItem("Export .csm"))
{
map->ExportToObjWIP(g_working_dir, g_scale, false, true, true);
}
ImGui::EndMenu();
}

ImGui::EndMenu();
Expand Down Expand Up @@ -3242,7 +3258,7 @@ void Gui::drawMenuBar()
if (fileSize(g_settings_path) == 0)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0359));
}
}
else
{
glfwTerminate();
Expand All @@ -3253,9 +3269,9 @@ void Gui::drawMenuBar()
std::quick_exit(0);
#endif
}
}
}
ImGui::EndMenu();
}
}

if (ImGui::BeginMenu(get_localized_string(LANG_0556).c_str(), (map && !map->is_mdl_model)))
{
Expand Down Expand Up @@ -8111,7 +8127,7 @@ void Gui::drawSettings()
ImGui::TextUnformatted(get_localized_string(LANG_0740).c_str());
ImGui::EndTooltip();
}
}
}
else if (settingsTab == 1)
{
for (size_t i = 0; i < g_settings.fgdPaths.size(); i++)
Expand Down Expand Up @@ -8639,7 +8655,7 @@ void Gui::drawSettings()
ImGui::EndChild();

ImGui::EndGroup();
}
}
ImGui::End();


Expand All @@ -8663,7 +8679,7 @@ void Gui::drawSettings()
}
oldShowSettings = showSettingsWidget = apply_settings_pressed;
}
}
}

void Gui::drawHelp()
{
Expand Down
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,12 +1051,15 @@ int main(int argc, char* argv[])

fs::current_path(bspguy_dir);


std::vector<UVVERT> vertices;
/*CSMFile tmpFile;
tmpFile.read("d:/SteamLibrary/steamapps/common/Half-Life/bspguy_work/de_dust2.smd/de_dust2_1.csm");
tmpFile.validate();
tmpFile.write("d:/SteamLibrary/steamapps/common/Half-Life/bspguy_work/de_dust2.smd/de_dust2_1_new.csm");*/
/*std::vector<UVVERT> vertices;
vec3 mins(-64.0f, -64.0f, -64.0f);
vec3 maxs(64.0f, 64.0f, 64.0f);
CreateSkybox(vertices, mins, maxs);
CreateSkybox(vertices, mins, maxs);*/

if (fileExists("./log.txt"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ vec3 findBestBrushCenter(std::vector<vec3>& points)
for (const auto& point : points) {
center += point;
}
center /= points.size();
center /= points.size() * 1.0f;

if (points.size() > 2)
{
Expand Down
Loading

0 comments on commit 765ed55

Please sign in to comment.