| 177 | } |
| 178 | |
| 179 | void 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 | |
| 236 | module::StaticModuleRegistration<ModelFormatManager> _staticModelFormatManagerModule; |
nothing calls this directly
no test coverage detected