20QSSGAssetImportManager::QSSGAssetImportManager(QObject *parent) : QObject(parent)
23 const QStringList keys = QSSGAssetImporterFactory::keys();
24 for (
const auto &key : keys) {
25 auto importer = QSSGAssetImporterFactory::create(key, QStringList());
27 m_assetImporters.append(importer);
29 for (
const auto &extension : importer->inputExtensions()) {
30 m_extensionsMap.insert(extension, importer);
33 qWarning() <<
"Failed to load asset import plugin with key: " << key;
53QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QString &filename,
54 const QDir &outputPath,
55 const QJsonObject &options,
58 QFileInfo fileInfo(filename);
61 if (!fileInfo.exists()) {
63 *error = QStringLiteral(
"file does not exist");
64 return ImportState::IoError;
68 const auto extension = fileInfo.suffix().toLower();
69 auto importer = m_extensionsMap.value(extension,
nullptr);
72 *error = QStringLiteral(
"unsupported file extension %1").arg(extension);
73 return ImportState::Unsupported;
76 QStringList generatedFiles;
77 auto errorString = importer->import(fileInfo.absoluteFilePath(), outputPath, options, &generatedFiles);
79 if (!errorString.isEmpty()) {
81 *error = QStringLiteral(
"%1").arg(errorString);
84 return ImportState::IoError;
88 for (
const auto &file : generatedFiles)
89 qDebug() <<
"generated file: " << file;
91 return ImportState::Success;
94QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
95 QSSGSceneDesc::Scene &scene,
98 return importFile(url, scene, {}, error);
101QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
102 QSSGSceneDesc::Scene &scene,
103 const QJsonObject &options,
106 auto importState = ImportState::Unsupported;
107 auto it = m_assetImporters.cbegin();
108 const auto end = m_assetImporters.cend();
109 for (; it != end; ++it) {
110 if ((*it)->name() == QLatin1String(
"assimp"))
115 const auto &importer = *it;
116 const auto ret = importer->import(url, options, scene);
117 if (!ret.isEmpty()) {
120 importState = ImportState::IoError;
122 importState = ImportState::Success;
129QJsonObject QSSGAssetImportManager::getOptionsForFile(
const QString &filename)
131 QFileInfo fileInfo(filename);
136 if (fileInfo.exists()) {
138 const auto extension = fileInfo.suffix().toLower();
139 auto importer = m_extensionsMap.value(extension,
nullptr);
141 options = importer->importOptions();
147QSSGAssetImportManager::PluginOptionMaps QSSGAssetImportManager::getAllOptions()
const
149 PluginOptionMaps options;
150 for (
const auto importer : m_assetImporters)
151 options.insert(importer->inputExtensions().join(QChar::fromLatin1(
':')), importer->importOptions());
155QHash<QString, QStringList> QSSGAssetImportManager::getSupportedExtensions()
const
157 QHash<QString, QStringList> extensionMap;
158 for (
const auto importer : std::as_const(m_assetImporters))
159 extensionMap.insert(importer->typeDescription(), importer->inputExtensions());
163QList<QSSGAssetImporterPluginInfo> QSSGAssetImportManager::getImporterPluginInfos()
const
165 QList<QSSGAssetImporterPluginInfo> output;
167 for (
const QSSGAssetImporter *importer : m_assetImporters) {
168 QSSGAssetImporterPluginInfo plugin;
169 plugin.name = importer->name();
170 plugin.inputExtensions = importer->inputExtensions();
171 plugin.outputExtension = importer->outputExtension();
172 plugin.type = importer->type();
173 plugin.importOptions = importer->importOptions();
174 plugin.typeDescription = importer->typeDescription();
175 output.push_back(plugin);