Skip to content

Commit

Permalink
Model export format can be specified in the preferences now, default …
Browse files Browse the repository at this point in the history
…is ASE.
  • Loading branch information
codereader committed Jul 29, 2017
1 parent 0eddb3d commit 47fc789
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/imodel.h
Expand Up @@ -215,6 +215,9 @@ inline model::ModelNodePtr Node_getModel(const scene::INodePtr& node)
return std::dynamic_pointer_cast<model::ModelNode>(node);
}

// Contains the default format used for exporting scaled models
const char* const RKEY_DEFAULT_MODEL_EXPORT_FORMAT = "user/ui/map/defaultScaledModelExportFormat";

const char* const MODULE_MODELFORMATMANAGER("ModelFormatManager");

inline model::IModelFormatManager& GlobalModelFormatManager()
Expand Down
1 change: 1 addition & 0 deletions install/user.xml
Expand Up @@ -26,6 +26,7 @@
<maxSnapshotFolderSize value="100" />
<loadStatusInterleave value="50" />
<saveStatusInterleave value="50" />
<defaultScaledModelExportFormat value="ase" />
</map>
<undo>
<queueSize value="256" />
Expand Down
23 changes: 23 additions & 0 deletions radiant/model/ModelFormatManager.cpp
@@ -1,6 +1,7 @@
#include "ModelFormatManager.h"

#include "itextstream.h"
#include "ipreferencesystem.h"
#include <boost/algorithm/string/case_conv.hpp>

#include "modulesystem/StaticModule.h"
Expand All @@ -25,6 +26,28 @@ void ModelFormatManager::initialiseModule(const ApplicationContext& ctx)
rMessage() << getName() << "::initialiseModule called." << std::endl;

_nullModelLoader.reset(new NullModelLoader);

module::ModuleRegistry::Instance().signal_allModulesInitialised().connect(
sigc::mem_fun(this, &ModelFormatManager::postModuleInitialisation)
);
}

void ModelFormatManager::postModuleInitialisation()
{
if (!_exporters.empty())
{
// Construct and Register the patch-related preferences
IPreferencePage& page = GlobalPreferenceSystem().getPage(_("Settings/Model Export"));

ComboBoxValueList choices;

for (const ExporterMap::value_type& pair : _exporters)
{
choices.push_back(pair.first);
}

page.appendCombo(_("Export Format for scaled Models"), RKEY_DEFAULT_MODEL_EXPORT_FORMAT, choices, true);
}
}

void ModelFormatManager::registerImporter(const IModelImporterPtr& importer)
Expand Down
3 changes: 3 additions & 0 deletions radiant/model/ModelFormatManager.h
Expand Up @@ -35,6 +35,9 @@ class ModelFormatManager :
void unregisterExporter(const IModelExporterPtr& exporter) override;

IModelExporterPtr getExporter(const std::string& extension) override;

private:
void postModuleInitialisation();
};

}
8 changes: 7 additions & 1 deletion radiant/model/ScaledModelExporter.cpp
Expand Up @@ -10,6 +10,7 @@
#include "os/path.h"
#include <boost/format.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <regex>

namespace map
Expand Down Expand Up @@ -70,7 +71,12 @@ void ScaledModelExporter::saveScaledModels()

void ScaledModelExporter::saveScaledModel(const scene::INodePtr& entityNode, const model::ModelNodePtr& modelNode)
{
std::string outputExtension = "lwo";
// Request the default format from the preferences
std::string outputExtension = registry::getValue<std::string>(RKEY_DEFAULT_MODEL_EXPORT_FORMAT);
boost::algorithm::to_lower(outputExtension);

rMessage() << "Model format used for export: " << outputExtension <<
" (this can be changed in the preferences)" << std::endl;

// Save the scaled model as ASE
model::IModelExporterPtr exporter = GlobalModelFormatManager().getExporter(outputExtension);
Expand Down

0 comments on commit 47fc789

Please sign in to comment.