Skip to content

Commit

Permalink
New feature: Duplicate BSP Structures!!
Browse files Browse the repository at this point in the history
New feature: Duplicate BSP Structures (as Duplicate BSP Model but using original model and not create copy)
  • Loading branch information
UnrealKaraulov committed Dec 18, 2023
1 parent fcbd273 commit 2b0ec83
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 54 deletions.
9 changes: 5 additions & 4 deletions cfg/language.ini
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ LANG_0460 = All Hulls
LANG_0461 = Simplify Hull
LANG_0462 = Redirect Hull
LANG_0463 = Print Hull Tree
LANG_0464 = Duplicate BSP model
LANG_0465 = Create a copy of this BSP model and assign to this entity.\n\nThis lets you edit the model for this entity without affecting others.
LANG_0466 = Export BSP model
LANG_0467 = With origin
LANG_0468 = With WAD
Expand Down Expand Up @@ -1077,7 +1075,6 @@ LANG_1083 = Copy
LANG_1084 = Ctrl+C
LANG_1085 = Delete
LANG_1086 = Del
LANG_1087 = Duplicate BSP model
LANG_1088 = ALT+G
LANG_1089 = Transform
LANG_1090 = Ctrl+M
Expand Down Expand Up @@ -1180,4 +1177,8 @@ LANG_SETTINGS_WADPATH = Resources path
LANG_SETTINGS_OPTIMIZE = Optimizing
LANG_SETTINGS_LIMITS = Limits
LANG_SETTINGS_RENDER = Rendering
LANG_SETTINGS_CONTROL = Controls
LANG_SETTINGS_CONTROL = Controls
LANG_DUPLICATE_BSP = Duplicate BSP model
LANG_CREATE_DUPLICATE_BSP = Create a new copy of BSP model and assign to this entity.\n\nThis lets you edit the model for this entity without affecting original model.
LANG_DUPLICATE_BSP_STRUCT = Unlock BSP model
LANG_CREATE_DUPLICATE_STRUCT = Create a new copy of BSP model structures.\n\nThis lets you edit the model assigned for this entity.
7 changes: 4 additions & 3 deletions cfg/language_ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ LANG_0460 = Все хуллы
LANG_0461 = Упростить хулл
LANG_0462 = Переназначить хулл
LANG_0463 = Вывести дерево хуллов
LANG_0464 = Дублировать браш-модель
LANG_0465 = Создаёт копию браш-модели, привязывая к ней эту же сущность.\n\nЭто позволит вам изменить модель сущности, не затрагивая другие.
LANG_0466 = Экспорт браш-модели
LANG_0467 = С оригином
LANG_0468 = Текстуры в WAD-файлах
Expand Down Expand Up @@ -1077,7 +1075,6 @@ LANG_1083 = Копировать
LANG_1084 = Ctrl+C
LANG_1085 = Удалить
LANG_1086 = Del
LANG_1087 = Дублировать браш-модель
LANG_1088 = ALT+G
LANG_1089 = Манипуляция
LANG_1090 = Ctrl+M
Expand Down Expand Up @@ -1181,3 +1178,7 @@ LANG_SETTINGS_OPTIMIZE = Оптимизация
LANG_SETTINGS_LIMITS = Лимиты
LANG_SETTINGS_RENDER = Рендеринг
LANG_SETTINGS_CONTROL = Управление
LANG_DUPLICATE_BSP = Дублировать браш-модель
LANG_CREATE_DUPLICATE_BSP = Создаёт новую копию браш-модели, привязывает к ней эту же сущность.\n\nПозволит редактировать модель не затрагивая оригинал.
LANG_DUPLICATE_BSP_STRUCT = Дублировать браш-структуры
LANG_CREATE_DUPLICATE_STRUCT = Создает копию струтур выбранной модели.\n\nПозволяет редактировать оригинал браш-модели.
55 changes: 53 additions & 2 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6155,7 +6155,7 @@ int Bsp::create_texinfo()
void Bsp::copy_bsp_model(int modelIdx, Bsp* targetMap, STRUCTREMAP& remap, std::vector<BSPPLANE>& newPlanes, std::vector<vec3>& newVerts,
std::vector<BSPEDGE32>& newEdges, std::vector<int>& newSurfedges, std::vector<BSPTEXTUREINFO>& newTexinfo,
std::vector<BSPFACE32>& newFaces, std::vector<COLOR3>& newLightmaps, std::vector<BSPNODE32>& newNodes,
std::vector<BSPCLIPNODE32>& newClipnodes)
std::vector<BSPCLIPNODE32>& newClipnodes, std::vector<WADTEX> & newTextures)
{
STRUCTUSAGE usage(this);
mark_model_structures(modelIdx, &usage, true);
Expand Down Expand Up @@ -6303,7 +6303,56 @@ void Bsp::copy_bsp_model(int modelIdx, Bsp* targetMap, STRUCTREMAP& remap, std::
}
}

void Bsp::duplicate_model_structures(int modelIdx)
{
std::vector<BSPPLANE> newPlanes;
std::vector<vec3> newVerts;
std::vector<BSPEDGE32> newEdges;
std::vector<int> newSurfedges;
std::vector<BSPTEXTUREINFO> newTexinfo;
std::vector<BSPFACE32> newFaces;
std::vector<COLOR3> newLightmaps;
std::vector<BSPNODE32> newNodes;
std::vector<BSPCLIPNODE32> newClipnodes;
std::vector<WADTEX> newTextures;

STRUCTREMAP remap(this);
copy_bsp_model(modelIdx, this, remap, newPlanes, newVerts, newEdges, newSurfedges, newTexinfo, newFaces, newLightmaps, newNodes, newClipnodes, newTextures);

if (newClipnodes.size())
append_lump(LUMP_CLIPNODES, &newClipnodes[0], sizeof(BSPCLIPNODE32) * newClipnodes.size());
if (newEdges.size())
append_lump(LUMP_EDGES, &newEdges[0], sizeof(BSPEDGE32) * newEdges.size());
if (newFaces.size())
{
append_lump(LUMP_FACES, &newFaces[0], sizeof(BSPFACE32) * newFaces.size());
}
if (newNodes.size())
append_lump(LUMP_NODES, &newNodes[0], sizeof(BSPNODE32) * newNodes.size());
if (newPlanes.size())
append_lump(LUMP_PLANES, &newPlanes[0], sizeof(BSPPLANE) * newPlanes.size());
if (newSurfedges.size())
append_lump(LUMP_SURFEDGES, &newSurfedges[0], sizeof(int) * newSurfedges.size());
if (newTexinfo.size())
append_lump(LUMP_TEXINFO, &newTexinfo[0], sizeof(BSPTEXTUREINFO) * newTexinfo.size());
if (newVerts.size())
append_lump(LUMP_VERTICES, &newVerts[0], sizeof(vec3) * newVerts.size());
if (newLightmaps.size())
{
append_lump(LUMP_LIGHTING, &newLightmaps[0], sizeof(COLOR3) * newLightmaps.size());
save_undo_lightmaps();
resize_all_lightmaps();
renderer->loadLightmaps();
}

BSPMODEL& oldModel = models[modelIdx];
oldModel.iFirstFace = remap.faces[oldModel.iFirstFace];
oldModel.iHeadnodes[0] = oldModel.iHeadnodes[0] < 0 ? -1 : remap.nodes[oldModel.iHeadnodes[0]];
for (int i = 1; i < MAX_MAP_HULLS; i++)
{
oldModel.iHeadnodes[i] = oldModel.iHeadnodes[i] < 0 ? -1 : remap.clipnodes[oldModel.iHeadnodes[i]];
}
}

int Bsp::duplicate_model(int modelIdx)
{
Expand All @@ -6316,9 +6365,10 @@ int Bsp::duplicate_model(int modelIdx)
std::vector<COLOR3> newLightmaps;
std::vector<BSPNODE32> newNodes;
std::vector<BSPCLIPNODE32> newClipnodes;
std::vector<WADTEX> newTextures;

STRUCTREMAP remap(this);
copy_bsp_model(modelIdx, this, remap, newPlanes, newVerts, newEdges, newSurfedges, newTexinfo, newFaces, newLightmaps, newNodes, newClipnodes);
copy_bsp_model(modelIdx, this, remap, newPlanes, newVerts, newEdges, newSurfedges, newTexinfo, newFaces, newLightmaps, newNodes, newClipnodes, newTextures);

if (newClipnodes.size())
append_lump(LUMP_CLIPNODES, &newClipnodes[0], sizeof(BSPCLIPNODE32) * newClipnodes.size());
Expand Down Expand Up @@ -6370,6 +6420,7 @@ int Bsp::duplicate_model(int modelIdx)
newModel.iHeadnodes[i] = oldModel.iHeadnodes[i] < 0 ? -1 : remap.clipnodes[oldModel.iHeadnodes[i]];
}
//newModel.nVisLeafs = 0; // techinically should match the old model, but leaves aren't duplicated yetx
// recalculate leafs
return newModelIdx;
}

Expand Down
3 changes: 2 additions & 1 deletion src/bsp/Bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ class Bsp
void copy_bsp_model(int modelIdx, Bsp* targetMap, STRUCTREMAP& remap, std::vector<BSPPLANE>& newPlanes, std::vector<vec3>& newVerts,
std::vector<BSPEDGE32>& newEdges, std::vector<int>& newSurfedges, std::vector<BSPTEXTUREINFO>& newTexinfo,
std::vector<BSPFACE32>& newFaces, std::vector<COLOR3>& newLightmaps, std::vector<BSPNODE32>& newNodes,
std::vector<BSPCLIPNODE32>& newClipnodes);
std::vector<BSPCLIPNODE32>& newClipnodes, std::vector<WADTEX>& newTextures);

int duplicate_model(int modelIdx);
void duplicate_model_structures(int modelIdx);
int add_model_to_worldspawn(int modelIdx);

// if the face's texinfo is not unique, a new one is created and returned. Otherwise, it's current texinfo is returned
Expand Down
27 changes: 13 additions & 14 deletions src/bsp/bsptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,22 @@ enum lump_copy_targets
FL_MODELS = 16384
};


enum clean_unused_lump
{
CLEAN_LIGHTMAP = 1,
CLEAN_PLANES = 2,
CLEAN_NODES = 4,
CLEAN_CLIPNODES = 8,
CLEAN_LEAVES = 16,
CLEAN_MARKSURFACES = 32,
CLEAN_FACES = 64,
CLEAN_SURFEDGES = 128,
CLEAN_TEXINFOS = 256,
CLEAN_EDGES = 512,
CLEAN_VERTICES = 1024,
CLEAN_TEXTURES = 2048,
CLEAN_VISDATA = 4096,
CLEAN_CLIPNODES_SOMETHING = 8192
CLEAN_TEXTURES = 4,
CLEAN_VERTICES = 8,
CLEAN_VISDATA = 16,
CLEAN_NODES = 32,
CLEAN_TEXINFOS = 64,
CLEAN_FACES = 128,
CLEAN_LIGHTMAP = 256,
CLEAN_CLIPNODES = 512,
CLEAN_LEAVES = 1024,
CLEAN_MARKSURFACES = 2048,
CLEAN_EDGES = 4096,
CLEAN_SURFEDGES = 8192,
CLEAN_CLIPNODES_SOMETHING = 16384
};

#define MAX_AMBIENTS 4
Expand Down
8 changes: 3 additions & 5 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ void BspRenderer::deleteRenderModel(RenderModel* renderModel)
return;
}



if (renderModel->renderGroups)
{
for (int k = 0; k < renderModel->groupCount; k++)
Expand Down Expand Up @@ -847,9 +845,9 @@ int BspRenderer::refreshModel(int modelIdx, bool refreshClipnodes, bool noTriang

renderModel->renderFaces = new RenderFace[model.nFaces];

std::vector<RenderGroup> renderGroups;
std::vector<std::vector<lightmapVert>> renderGroupVerts;
std::vector<std::vector<lightmapVert>> renderGroupWireframeVerts;
std::vector<RenderGroup> renderGroups{};
std::vector<std::vector<lightmapVert>> renderGroupVerts{};
std::vector<std::vector<lightmapVert>> renderGroupWireframeVerts{};

for (int i = 0; i < model.nFaces; i++)
{
Expand Down
3 changes: 3 additions & 0 deletions src/editor/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ void DuplicateBspModelCommand::execute()
pickCount++;
vertPickCount++;


map->remove_unused_model_structures(CLEAN_LEAVES);

g_app->gui->refresh();

/*
Expand Down
Loading

0 comments on commit 2b0ec83

Please sign in to comment.