22QSSGAssetImportManager::QSSGAssetImportManager(QObject *parent) : QObject(parent)
25 const QStringList keys = QSSGAssetImporterFactory::keys();
26 for (
const auto &key : keys) {
27 auto importer = QSSGAssetImporterFactory::create(key, QStringList());
29 m_assetImporters.append(importer);
34 const auto extensions = importer->inputExtensions();
35 for (
const auto &extension : extensions) {
36 const QString extensionKey = extension.toLower();
37 const auto existing = m_extensionsMap.constFind(extensionKey);
38 if (existing == m_extensionsMap.cend() || (*existing)->priority() < importer->priority())
39 m_extensionsMap.insert(extensionKey, importer);
42 qWarning() <<
"Failed to load asset import plugin with key: " << key;
61QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QString &filename,
62 const QDir &outputPath,
63 const QJsonObject &options,
66 QFileInfo fileInfo(filename);
69 if (!fileInfo.exists()) {
71 *error = QStringLiteral(
"file does not exist");
72 return ImportState::IoError;
76 const auto extension = fileInfo.suffix().toLower();
77 auto importer = m_extensionsMap.value(extension,
nullptr);
80 *error = QStringLiteral(
"unsupported file extension %1").arg(extension);
81 return ImportState::Unsupported;
84 QStringList generatedFiles;
85 auto errorString = importer->import(fileInfo.absoluteFilePath(), outputPath, options, &generatedFiles);
87 if (!errorString.isEmpty()) {
89 *error = QStringLiteral(
"%1").arg(errorString);
92 return ImportState::IoError;
96 for (
const auto &file : std::as_const(generatedFiles))
97 qDebug() <<
"generated file: " << file;
99 return ImportState::Success;
102QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
103 QSSGSceneDesc::Scene &scene,
106 return importFile(url, scene, {}, error);
109QSSGAssetImportManager::ImportState QSSGAssetImportManager::importFile(
const QUrl &url,
110 QSSGSceneDesc::Scene &scene,
111 const QJsonObject &options,
117 const QString filePath = QQmlFile::isLocalFile(url) ? QQmlFile::urlToLocalFileOrQrc(url) : url.path();
119 const auto extension = QFileInfo(filePath).suffix().toLower();
120 auto importer = m_extensionsMap.value(extension,
nullptr);
123 *error = QStringLiteral(
"unsupported file extension %1").arg(extension);
124 return ImportState::Unsupported;
127 const auto ret = importer->import(url, options, scene);
128 if (!ret.isEmpty()) {
131 return ImportState::IoError;
134 return ImportState::Success;
137QJsonObject QSSGAssetImportManager::getOptionsForFile(
const QString &filename)
139 QFileInfo fileInfo(filename);
144 if (fileInfo.exists()) {
146 const auto extension = fileInfo.suffix().toLower();
147 auto importer = m_extensionsMap.value(extension,
nullptr);
149 options = importer->importOptions();
155QSSGAssetImportManager::PluginOptionMaps QSSGAssetImportManager::getAllOptions()
const
157 PluginOptionMaps options;
158 for (
const auto importer : m_assetImporters)
159 options.insert(importer->inputExtensions().join(QChar::fromLatin1(
':')), importer->importOptions());
163QHash<QString, QStringList> QSSGAssetImportManager::getSupportedExtensions()
const
165 QHash<QString, QStringList> extensionMap;
166 for (
const auto importer : std::as_const(m_assetImporters))
167 extensionMap.insert(importer->typeDescription(), importer->inputExtensions());
171QList<QSSGAssetImporterPluginInfo> QSSGAssetImportManager::getImporterPluginInfos()
const
173 QList<QSSGAssetImporterPluginInfo> output;
175 for (
const QSSGAssetImporter *importer : m_assetImporters) {
176 QSSGAssetImporterPluginInfo plugin;
177 plugin.name = importer->name();
178 plugin.inputExtensions = importer->inputExtensions();
179 plugin.outputExtension = importer->outputExtension();
180 plugin.type = importer->type();
181 plugin.importOptions = importer->importOptions();
182 plugin.typeDescription = importer->typeDescription();
183 output.push_back(plugin);