1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtQml/qqmlextensionplugin.h>
5#include <QtQml/qqml.h>
6#include <QtQuick3D/qquick3dobject.h>
7
8#include <QtQuick3D/private/qquick3dcamera_p.h>
9#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
10#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
11#include <QtQuick3D/private/qquick3dfrustumcamera_p.h>
12#include <QtQuick3D/private/qquick3dcustomcamera_p.h>
13
14#include <QtQuick3D/private/qquick3ddefaultmaterial_p.h>
15#include <QtQuick3D/private/qquick3dtexture_p.h>
16#include <QtQuick3D/private/qquick3ddirectionallight_p.h>
17#include <QtQuick3D/private/qquick3dpointlight_p.h>
18#include <QtQuick3D/private/qquick3dspotlight_p.h>
19#include <QtQuick3D/private/qquick3dmaterial_p.h>
20#include <QtQuick3D/private/qquick3dmodel_p.h>
21#include <QtQuick3D/private/qquick3dskeleton_p.h>
22#include <QtQuick3D/private/qquick3djoint_p.h>
23#include <QtQuick3D/private/qquick3dmorphtarget_p.h>
24#include <QtQuick3D/private/qquick3dnode_p.h>
25#include <QtQuick3D/private/qquick3dviewport_p.h>
26#include <QtQuick3D/private/qquick3dsceneenvironment_p.h>
27#include <QtQuick3D/private/qquick3dpickresult_p.h>
28#include <QtQuick3D/private/qquick3drepeater_p.h>
29#include <QtQuick3D/private/qquick3dloader_p.h>
30#include <QtQuick3D/private/qquick3dprincipledmaterial_p.h>
31#include <QtQuick3D/private/qquick3drenderstats_p.h>
32#include <QtQuick3D/private/qquick3dgeometry_p.h>
33#include <QtQuick3D/private/qquick3dquaternionutils_p.h>
34#include <QtQuick3D/private/qquick3dquaternionanimation_p.h>
35#include <QtQuick3D/private/qquick3dtexturedata_p.h>
36#include <QtQuick3D/private/qquick3dreflectionprobe_p.h>
37#include <QtQuick3D/private/qquick3dbakedlightmap_p.h>
38#include <QtQuick3D/private/qquick3dlightmapper_p.h>
39
40#include <private/qqmlglobal_p.h>
41
42
43static void initResources()
44{
45#ifdef QT_STATIC
46 Q_INIT_RESOURCE(qmake_QtQuick3D);
47 Q_INIT_RESOURCE(res);
48#endif
49}
50
51QT_BEGIN_NAMESPACE
52
53Q_GHS_KEEP_REFERENCE(qml_register_types_QtQuick3D);
54
55static QQmlPrivate::AutoParentResult qquick3dobject_autoParent(QObject *obj, QObject *parent)
56{
57 // When setting a parent (especially during dynamic object creation) in QML,
58 // also try to set up the analogous item/window relationship.
59 if (QQuick3DObject *parentItem = qmlobject_cast<QQuick3DObject *>(object: parent)) {
60 QQuick3DObject *item = qmlobject_cast<QQuick3DObject *>(object: obj);
61 if (item) {
62 // An Item has another Item
63 item->setParentItem(parentItem);
64 return QQmlPrivate::Parented;
65 }
66 return QQmlPrivate::IncompatibleObject;
67 } else if (qmlobject_cast<QQuick3DObject *>(object: obj)) {
68 return QQmlPrivate::IncompatibleParent;
69 }
70 return QQmlPrivate::IncompatibleObject;
71}
72
73static void qt_quick3d_defineModule()
74{
75 QQmlPrivate::RegisterAutoParent autoparent = { .structVersion: 0, .function: &qquick3dobject_autoParent };
76 QQmlPrivate::qmlregister(QQmlPrivate::AutoParentRegistration, &autoparent);
77
78 qRegisterMetaType<QQuick3DPickResult>();
79 qRegisterMetaType<QQuick3DRenderStats *>();
80 qRegisterMetaType<QQuick3DBounds3>();
81
82}
83
84class QQuick3DPlugin : public QQmlEngineExtensionPlugin
85{
86 Q_OBJECT
87 Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
88
89public:
90 QQuick3DPlugin(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent)
91 {
92 volatile auto registration = &qml_register_types_QtQuick3D;
93 Q_UNUSED(registration);
94 qt_quick3d_defineModule();
95 initResources();
96 }
97};
98
99QT_END_NAMESPACE
100
101#include "plugin.moc"
102

source code of qtquick3d/src/quick3d/plugin.cpp