Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dlightmapbaker.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
6
8
14
16{
17 if (m_lmWindow) {
18 m_lmWindow->close();
19 delete m_lmWindow;
20 }
21
22 delete m_bakingControl;
23}
24
32void QQuick3DLightmapBaker::bake(Callback callback)
33{
34 Q_ASSERT(m_view);
35 m_bakingRequested = true;
36 m_bakingControl->reset();
37 m_callback = callback;
38 updateView();
39}
40
45{
46 Q_ASSERT(m_view);
47 m_bakingRequested = true;
48 m_bakingControl->reset();
49
50 m_windowCancelRequested = false;
51 if (m_lmWindow)
52 m_lmWindow->close();
53
54 m_lmWindow = new QQuickView();
55 m_lmWindow->setSource(QUrl::fromLocalFile(QStringLiteral(":/qt-project.org/imports/QtQuick3D/Helpers/impl/LightmapperOutputWindow.qml")));
56 m_lmWindow->show();
57 m_lmWindow->setProperty("width", 400);
58 m_lmWindow->setProperty("height", 400);
59
60 QObject *rootObject = m_lmWindow->rootObject();
61 QObject *cancelButton = rootObject->findChild<QObject*>(QStringLiteral("cancelButton"));
62 if (cancelButton)
63 QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(onLmCancelButtonClicked()));
64
65 QObject::connect(m_lmWindow, &QQuickWindow::closing, this, &QQuick3DLightmapBaker::onLmWindowClosing);
66
67 m_callback = [this, rootObject] (
68 BakingStatus status,
69 std::optional<QString> msg,
70 BakingControl *bakingControl) {
71
72 QQuickWindow *window = m_view->window();
73 if (status == BakingStatus::Complete) {
75 updateView();
76 QQuickWindowPrivate::get(window)->updatesEnabled = true;
77 } else if (status != BakingStatus::None) {
78 if (status == BakingStatus::Progress)
79 QQuickWindowPrivate::get(window)->updatesEnabled = false;
80 else if (status == BakingStatus::Cancelled)
81 QQuickWindowPrivate::get(window)->updatesEnabled = true;
82
83 if (msg.has_value()) {
84 QString result = msg.value();
85 if (status == BakingStatus::Warning)
86 result.prepend(QStringLiteral("Warning: "));
87 else if (status == BakingStatus::Error)
88 result.prepend(QStringLiteral("Error: "));
89
91 "appendText",
93 }
94
95 if (m_windowCancelRequested && !bakingControl->isCancelled())
96 bakingControl->requestCancel();
97 }
98 };
99
100 updateView();
101}
102
103void QQuick3DLightmapBaker::updateView()
104{
106}
107
108void QQuick3DLightmapBaker::onLmCancelButtonClicked()
109{
110 if (m_windowCancelRequested)
111 return;
112
113 m_windowCancelRequested = true;
114}
115
116void QQuick3DLightmapBaker::onLmWindowClosing(QQuickCloseEvent *event)
117{
119
120 onLmCancelButtonClicked();
121}
122
124 if (isCancelled())
125 cancelFlag.store(0, std::memory_order_release);
126}
127
129 if (!isCancelled())
130 cancelFlag.store(1, std::memory_order_release);
131}
132
134 return cancelFlag.load(std::memory_order_acquire) == 1;
135}
136
\inmodule QtCore
Definition qobject.h:103
T findChild(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
Definition qobject.h:155
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
QQuick3DLightmapBaker(QQuick3DViewport *view)
\qmlsignal QtQuick::Window::sceneGraphError(SceneGraphError error, QString message)
QQuickWindow * window() const
Returns the window in which this item is rendered.
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:20
void setSource(const QUrl &)
Sets the source to the url, loads the QML component and instantiates it.
QQuickItem * rootObject() const
Returns the view's root \l {QQuickItem} {item}.
static QQuickWindowPrivate * get(QQuickWindow *c)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString & prepend(QChar c)
Definition qstring.h:478
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
void show()
Shows the window.
Definition qwindow.cpp:2254
bool close()
Close the window.
Definition qwindow.cpp:2354
Combined button and popup list for selecting options.
@ QueuedConnection
#define SLOT(a)
Definition qobjectdefs.h:52
#define Q_ARG(Type, data)
Definition qobjectdefs.h:63
#define SIGNAL(a)
Definition qobjectdefs.h:53
struct _cl_event * event
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define Q_UNUSED(x)
aWidget window() -> setWindowTitle("New Window Title")
[2]
QQuickView * view
[0]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...