MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / exportSelectedAsModel

Function exportSelectedAsModel

radiantcore/map/algorithm/Export.cpp:47–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47void exportSelectedAsModel(const model::ModelExportOptions& options)
48{
49 if (!path_is_absolute(options.outputFilename.c_str()))
50 {
51 throw cmd::ExecutionNotPossible(_("Output path must be absolute."));
52 }
53
54 std::string outputFormat = options.outputFormat;
55
56 // Request the default format from the preferences
57 if (outputFormat.empty())
58 {
59 outputFormat = registry::getValue<std::string>(RKEY_DEFAULT_MODEL_EXPORT_FORMAT);
60 }
61
62 string::to_lower(outputFormat);
63
64 rMessage() << "Model format used for export: " << outputFormat << std::endl;
65
66 // Get the output format
67 model::IModelExporterPtr expFormat = GlobalModelFormatManager().getExporter(outputFormat);
68
69 // Instantiate a ModelExporter to do the footwork
70 model::ModelExporter exporter(expFormat);
71
72 // Collect exportables
73 // Call the traverseSelected function to hit the exporter with each node
74 traverseSelected(GlobalSceneGraph().root(), exporter);
75
76 exporter.setCenterObjects(options.exportOrigin != model::ModelExportOrigin::MapOrigin);
77 exporter.setSkipCaulkMaterial(options.skipCaulk);
78 exporter.setExportLightsAsObjects(options.exportLightsAsObjects);
79
80 if (options.exportOrigin == model::ModelExportOrigin::EntityOrigin)
81 {
82 // Find the specified entity
83 Entity* foundEntity = nullptr;
84
85 GlobalSelectionSystem().foreachSelected([&](const scene::INodePtr& node)
86 {
87 auto entity = Node_getEntity(node);
88 if (!foundEntity && entity && entity->getKeyValue("name") == options.entityName)
89 {
90 foundEntity = entity;
91 }
92 });
93
94 if (foundEntity == nullptr)
95 {
96 throw cmd::ExecutionFailure(fmt::format(_("Could not find the entity with name {0}"), options.entityName));
97 }
98
99 exporter.setOrigin(string::convert<Vector3>(foundEntity->getKeyValue("origin")));
100 exporter.setCenterObjects(true);
101 }
102 else if (options.exportOrigin == model::ModelExportOrigin::CustomOrigin)
103 {
104 exporter.setOrigin(options.customExportOrigin);

Callers 1

exportSelectedAsModelCmdFunction · 0.85

Calls 15

path_is_absoluteFunction · 0.85
to_lowerFunction · 0.85
rMessageFunction · 0.85
traverseSelectedFunction · 0.85
Node_getEntityFunction · 0.85
ExecutionFailureClass · 0.85
standardPathFunction · 0.85
getFilenameFunction · 0.85
getDirectoryFunction · 0.85
getRelativePathFunction · 0.85
getAllLayersOfSelectionFunction · 0.85

Tested by

no test coverage detected