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

Method convertModelCmd

radiantcore/model/ModelFormatManager.cpp:179–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177}
178
179void ModelFormatManager::convertModelCmd(const cmd::ArgumentList& args)
180{
181 if (args.size() != 3)
182 {
183 rWarning() << "Usage: ConvertModel <InputPath> <OutputPath> <ExportFormat>" << std::endl;
184 return;
185 }
186
187 auto inputPath = args[0].getString();
188 auto outputPathRaw = args[1].getString();
189 auto outputFormat = args[2].getString();
190
191 // Get the exporter
192 auto exporter = getExporter(outputFormat);
193
194 if (!exporter)
195 {
196 throw cmd::ExecutionFailure(fmt::format(_("Could not find any exporter for this format: {0}"), outputFormat));
197 }
198
199 // Load the input model
200 IModelPtr model;
201
202 foreachImporter([&](const model::IModelImporterPtr& importer)
203 {
204 if (!model)
205 {
206 model = importer->loadModelFromPath(inputPath);
207 }
208 });
209
210 if (!model)
211 {
212 throw cmd::ExecutionFailure(fmt::format(_("Could not load model file {0}"), inputPath));
213 }
214
215 // Stream all model surfaces to the exporter
216 for (int i = 0; i < model->getSurfaceCount(); ++i)
217 {
218 auto& surface = model->getSurface(static_cast<unsigned int>(i));
219 exporter->addSurface(surface, Matrix4::getIdentity());
220 }
221
222 fs::path outputPath = outputPathRaw;
223
224 rMessage() << "Exporting model to " << outputPath.string() << std::endl;
225
226 try
227 {
228 exporter->exportToPath(outputPath.parent_path().string(), outputPath.filename().string());
229 }
230 catch (const std::runtime_error& ex)
231 {
232 throw cmd::ExecutionFailure(fmt::format(_("Failed to export model to {0}: {1}"), outputPath.string(), ex.what()));
233 }
234}
235
236module::StaticModuleRegistration<ModelFormatManager> _staticModelFormatManagerModule;

Callers

nothing calls this directly

Calls 14

rWarningFunction · 0.85
ExecutionFailureClass · 0.85
rMessageFunction · 0.85
getSurfaceMethod · 0.80
stringMethod · 0.80
whatMethod · 0.80
formatFunction · 0.50
_Function · 0.50
sizeMethod · 0.45
getStringMethod · 0.45
loadModelFromPathMethod · 0.45
getSurfaceCountMethod · 0.45

Tested by

no test coverage detected