1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3D_ASSIMPIMPORTER_H
5#define QT3D_ASSIMPIMPORTER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18// ASSIMP LIBRARY INCLUDE
19#include <assimp/Importer.hpp>
20#include <assimp/scene.h>
21#include <assimp/postprocess.h>
22#include <assimp/DefaultLogger.hpp>
23
24#include <QtCore/QDir>
25#include <QtCore/QHash>
26#include <QtCore/QList>
27#include <QtCore/QLoggingCategory>
28
29#include "assimphelpers.h"
30
31#include <Qt3DRender/private/qsceneimporter_p.h>
32
33QT_BEGIN_NAMESPACE
34
35class QFile;
36
37namespace Qt3DCore {
38class QCamera;
39}
40
41namespace Qt3DAnimation {
42class QKeyframeAnimation;
43class QMorphingAnimation;
44}
45
46namespace Qt3DRender {
47
48class QMaterial;
49class QAbstractTexture;
50class QAbstractLight;
51class QGeometryRenderer;
52
53Q_DECLARE_LOGGING_CATEGORY(AssimpImporterLog)
54
55class AssimpImporter : public QSceneImporter
56{
57 Q_OBJECT
58
59public:
60 AssimpImporter();
61 ~AssimpImporter();
62
63 // SceneParserInterface interface
64 void setSource(const QUrl& source) override;
65 void setData(const QByteArray& data, const QString &basePath) override;
66 bool areFileTypesSupported(const QStringList &extensions) const override;
67 Qt3DCore::QEntity *scene(const QString &id = QString()) override;
68 Qt3DCore::QEntity *node(const QString &id) override;
69
70private:
71 static bool areAssimpExtensions(const QStringList &extensions);
72 static QStringList assimpSupportedFormats();
73
74 Qt3DCore::QEntity *node(aiNode *node);
75
76 void readSceneFile(const QString &file);
77 void readSceneData(const QByteArray& data, const QString &basePath);
78
79 void cleanup();
80 void parse();
81
82 QMaterial *loadMaterial(uint materialIndex);
83 QGeometryRenderer *loadMesh(uint meshIndex);
84 QAbstractTexture *loadEmbeddedTexture(uint textureIndex);
85 QAbstractLight *loadLight(uint lightIndex);
86 Qt3DCore::QEntity *loadCamera(aiNode *node);
87 void loadAnimation(uint animationIndex);
88
89 void copyMaterialName(QMaterial *material, aiMaterial *assimpMaterial);
90 void copyMaterialColorProperties(QMaterial *material, aiMaterial *assimpMaterial);
91 void copyMaterialFloatProperties(QMaterial *material, aiMaterial *assimpMaterial);
92 void copyMaterialBoolProperties(QMaterial *material, aiMaterial *assimpMaterial);
93 void copyMaterialShadingModel(QMaterial *material, aiMaterial *assimpMaterial);
94 void copyMaterialBlendingFunction(QMaterial *material, aiMaterial *assimpMaterial);
95 void copyMaterialTextures(QMaterial *material, aiMaterial *assimpMaterial);
96
97 class SceneImporter {
98 public :
99
100 SceneImporter();
101 ~SceneImporter();
102
103 Assimp::Importer *m_importer;
104 mutable const aiScene *m_aiScene;
105
106 QHash<aiTextureType, QString> m_textureToParameterName;
107 QList<Qt3DAnimation::QKeyframeAnimation *> m_animations;
108 QList<Qt3DAnimation::QMorphingAnimation *> m_morphAnimations;
109 };
110
111 QDir m_sceneDir;
112 bool m_sceneParsed;
113 AssimpImporter::SceneImporter *m_scene;
114 static QStringList assimpSupportedFormatsList;
115};
116
117} // namespace Qt3DRender
118
119QT_END_NAMESPACE
120
121#endif // QT3D_ASSIMPIMPORTER_H
122

source code of qt3d/src/plugins/sceneparsers/assimp/assimpimporter.h