Skip to content

Commit

Permalink
#5687: Adjust model exporter code to preserve the layers of the repla…
Browse files Browse the repository at this point in the history
…ced selection
  • Loading branch information
codereader committed Sep 2, 2021
1 parent 0498b0d commit 5f4e137
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion radiantcore/map/algorithm/Export.cpp
Expand Up @@ -27,6 +27,20 @@ namespace map
namespace algorithm
{

// Returns the union set of layer IDs of the current selection
scene::LayerList getAllLayersOfSelection()
{
scene::LayerList unionSet;

GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
{
const auto& layers = node->getLayers();
unionSet.insert(layers.begin(), layers.end());
});

return unionSet;
}

void exportSelectedAsModel(const ModelExportOptions& options)
{
if (!path_is_absolute(options.outputFilename.c_str()))
Expand Down Expand Up @@ -112,7 +126,8 @@ void exportSelectedAsModel(const ModelExportOptions& options)
auto lastSelectedNode = GlobalSelectionSystem().ultimateSelected();
auto lastSelectedEntity = Node_getEntity(lastSelectedNode);

// Remove the selection
// Remove the selection, but remember its layers first
auto previousLayerSet = getAllLayersOfSelection();
selection::algorithm::deleteSelection();

// Create a func_static in its place
Expand All @@ -130,6 +145,7 @@ void exportSelectedAsModel(const ModelExportOptions& options)

auto newEntity = Node_getEntity(modelNode);
newEntity->setKeyValue("model", relativeModelPath);
modelNode->assignToLayers(previousLayerSet);

if (lastSelectedEntity)
{
Expand Down

0 comments on commit 5f4e137

Please sign in to comment.