| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qquick3dbakedlightmap_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | \qmltype BakedLightmap |
| 10 | \inherits QtObject |
| 11 | \inqmlmodule QtQuick3D |
| 12 | \brief Specifies baked lightmap settings for a model. |
| 13 | \since 6.4 |
| 14 | |
| 15 | A BakedLightmap object can be used to enable: |
| 16 | |
| 17 | \list |
| 18 | \li persistently storing the baked lightmap data - during baking, or |
| 19 | \li loading the previously generated and stored lightmaps - at run time. |
| 20 | \endlist |
| 21 | |
| 22 | A Model with \l{Model::usedInBakedLighting}{usedInBakedLighting} set to |
| 23 | true is considered to be part of the raytraced scene when baking lightmaps, |
| 24 | meaning the model's geometry and material contribute to direct and indirect |
| 25 | lighting. This on its own does not however enable generating, including |
| 26 | full calculation of bounced indirect lighting, and finally saving a |
| 27 | lightmap for the model. To do that, the model also needs to be associated |
| 28 | with an \l enabled BakedLightmap object with a unique key set. |
| 29 | |
| 30 | When running in normal mode, the same BakedLightmap object indicates that |
| 31 | the Model has lightmap data, and that the engine should attempt to load |
| 32 | this data (based on the unique key) and use it when rendering. |
| 33 | |
| 34 | For more information on how to bake lightmaps, see the \l Lightmapper |
| 35 | documentation. |
| 36 | |
| 37 | \note As of Qt 6.4, lightmap baking is in an early technical preview state. |
| 38 | Changes to features, quality, and API are likely happen in future releases. |
| 39 | |
| 40 | \sa Lightmapper, Model::usedInBakedLighting |
| 41 | */ |
| 42 | |
| 43 | /*! |
| 44 | \qmlproperty bool BakedLightmap::enabled |
| 45 | |
| 46 | When false, the lightmap generated for the model is not stored during |
| 47 | lightmap baking, even though \l key is set to a non-empty value. |
| 48 | |
| 49 | The default value is true. |
| 50 | */ |
| 51 | |
| 52 | /*! |
| 53 | \qmlproperty string BakedLightmap::key |
| 54 | |
| 55 | When non-empty and \l enabled is true, the lightmap generated for the model |
| 56 | is stored persistently during lightmap baking. The value should be a unique |
| 57 | string that is fit to be included in the name of a file in the filesystem. |
| 58 | No other Model in the scene must use the same key. |
| 59 | |
| 60 | The default value is empty. |
| 61 | |
| 62 | \sa loadPrefix |
| 63 | */ |
| 64 | |
| 65 | /*! |
| 66 | \qmlproperty string BakedLightmap::loadPrefix |
| 67 | |
| 68 | When non-empty, the value is prepended as a path to the value of \l key |
| 69 | when loading the lightmap for the Model. This allows shipping the generated |
| 70 | lightmaps in different location than they were written to, for example as |
| 71 | embedded resources via the Qt resource system. |
| 72 | |
| 73 | For example, the following enables lightmap generation for a static model, |
| 74 | using a unique key for identifying the lightmap data between baking and |
| 75 | real runs of the application. Once baking is performed, the generated file |
| 76 | can be listed in the application's CMake project as a resource under the |
| 77 | \c{/lightmaps} PREFIX, letting the build process pick up the file and |
| 78 | include it in the executable. |
| 79 | |
| 80 | \qml |
| 81 | Model { |
| 82 | source: "model.mesh" |
| 83 | y: 10 |
| 84 | bakedLightmap: BakedLightmap { |
| 85 | key: "model34156" |
| 86 | loadPrefix: "qrc:/lightmaps" |
| 87 | // will attempt to load from :/lightmaps/qlm_model34156.exr at run time |
| 88 | } |
| 89 | } |
| 90 | \endqml |
| 91 | |
| 92 | The default value is empty. |
| 93 | |
| 94 | \sa key |
| 95 | */ |
| 96 | |
| 97 | bool QQuick3DBakedLightmap::isEnabled() const |
| 98 | { |
| 99 | return m_enabled; |
| 100 | } |
| 101 | |
| 102 | void QQuick3DBakedLightmap::setEnabled(bool enabled) |
| 103 | { |
| 104 | if (m_enabled == enabled) |
| 105 | return; |
| 106 | |
| 107 | m_enabled = enabled; |
| 108 | emit enabledChanged(); |
| 109 | emit changed(); |
| 110 | } |
| 111 | |
| 112 | QString QQuick3DBakedLightmap::key() const |
| 113 | { |
| 114 | return m_key; |
| 115 | } |
| 116 | |
| 117 | void QQuick3DBakedLightmap::setKey(const QString &key) |
| 118 | { |
| 119 | if (m_key == key) |
| 120 | return; |
| 121 | |
| 122 | m_key = key; |
| 123 | emit keyChanged(); |
| 124 | emit changed(); |
| 125 | } |
| 126 | |
| 127 | QString QQuick3DBakedLightmap::loadPrefix() const |
| 128 | { |
| 129 | return m_loadPrefix; |
| 130 | } |
| 131 | |
| 132 | void QQuick3DBakedLightmap::setLoadPrefix(const QString &loadPrefix) |
| 133 | { |
| 134 | if (m_loadPrefix == loadPrefix) |
| 135 | return; |
| 136 | |
| 137 | m_loadPrefix = loadPrefix; |
| 138 | emit loadPrefixChanged(); |
| 139 | emit changed(); |
| 140 | } |
| 141 | |
| 142 | QT_END_NAMESPACE |
| 143 | |