18QSSGAssetImportManager::QSSGAssetImportManager(QObject *parent) : QObject(parent)
21 const QStringList keys = QSSGAssetImporterFactory::keys();
22 for (
const auto &key : keys) {
23 auto importer = QSSGAssetImporterFactory::create(key, QStringList());
25 m_assetImporters.append(importer);
27 for (
const auto &extension : importer->inputExtensions()) {
28 m_extensionsMap.insert(extension, importer);
31 qWarning() <<
"Failed to load asset import plugin with key: " << key;
51QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QString &filename,
52 const QDir &outputPath,
53 const QJsonObject &options,
56 QFileInfo fileInfo(filename);
59 if (!fileInfo.exists()) {
61 *error = QStringLiteral(
"file does not exist");
62 return ImportState::IoError;
66 const auto extension = fileInfo.suffix().toLower();
67 auto importer = m_extensionsMap.value(extension,
nullptr);
70 *error = QStringLiteral(
"unsupported file extension %1").arg(extension);
71 return ImportState::Unsupported;
74 QStringList generatedFiles;
75 auto errorString = importer->import(fileInfo.absoluteFilePath(), outputPath, options, &generatedFiles);
77 if (!errorString.isEmpty()) {
79 *error = QStringLiteral(
"%1").arg(errorString);
82 return ImportState::IoError;
86 for (
const auto &file : generatedFiles)
87 qDebug() <<
"generated file: " << file;
89 return ImportState::Success;
92QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
93 QSSGSceneDesc::Scene &scene,
96 return importFile(url, scene, {}, error);
99QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
100 QSSGSceneDesc::Scene &scene,
101 const QJsonObject &options,
104 auto importState = ImportState::Unsupported;
105 auto it = m_assetImporters.cbegin();
106 const auto end = m_assetImporters.cend();
107 for (; it != end; ++it) {
108 if ((*it)->name() == QLatin1String(
"assimp"))
113 const auto &importer = *it;
114 const auto ret = importer->import(url, options, scene);
115 if (!ret.isEmpty()) {
118 importState = ImportState::IoError;
120 importState = ImportState::Success;
127QJsonObject QSSGAssetImportManager::getOptionsForFile(
const QString &filename)
129 QFileInfo fileInfo(filename);
134 if (fileInfo.exists()) {
136 const auto extension = fileInfo.suffix().toLower();
137 auto importer = m_extensionsMap.value(extension,
nullptr);
139 options = importer->importOptions();
145QSSGAssetImportManager::PluginOptionMaps QSSGAssetImportManager::getAllOptions()
const
147 PluginOptionMaps options;
148 for (
const auto importer : m_assetImporters)
149 options.insert(importer->inputExtensions().join(QChar::fromLatin1(
':')), importer->importOptions());
153QHash<QString, QStringList> QSSGAssetImportManager::getSupportedExtensions()
const
155 QHash<QString, QStringList> extensionMap;
156 for (
const auto importer : std::as_const(m_assetImporters))
157 extensionMap.insert(importer->typeDescription(), importer->inputExtensions());
161QList<QSSGAssetImporterPluginInfo> QSSGAssetImportManager::getImporterPluginInfos()
const
163 QList<QSSGAssetImporterPluginInfo> output;
165 for (
const QSSGAssetImporter *importer : m_assetImporters) {
166 QSSGAssetImporterPluginInfo plugin;
167 plugin.name = importer->name();
168 plugin.inputExtensions = importer->inputExtensions();
169 plugin.outputExtension = importer->outputExtension();
170 plugin.type = importer->type();
171 plugin.importOptions = importer->importOptions();
172 plugin.typeDescription = importer->typeDescription();
173 output.push_back(plugin);