1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "lightmapfile.h"
#include "lightmapimageprovider.h"
#include "lightmapviewerhelpers.h"
#include <QCoreApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDebug>
int main(int argc, char *argv[])
{
QString input;
// We Handle all the command line parts first in its own QCoreApplication
// since we don't want to create a gui application which would not work if
// running through ssh for instance.
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("Qt LightmapViewer");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.setApplicationDescription("A tool for viewing Qt's baked lightmaps");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption printOption("print", "Print the content of the lightmap");
QCommandLineOption extractOption("extract", "Extract the lightmap contents into the current working directory");
parser.addOption(printOption);
parser.addOption(extractOption);
parser.addPositionalArgument("input", "Optional path to lightmap");
parser.process(app);
bool doPrint = parser.isSet(printOption);
bool doExtract = parser.isSet(extractOption);
const QStringList positionalArgs = parser.positionalArguments();
input = positionalArgs.isEmpty() ? QString() : positionalArgs.first();
if (doPrint && input.isEmpty()) {
qFatal() << "Print option selected with no lightmap.";
return 1;
}
if (doExtract && input.isEmpty()) {
qFatal() << "Extract option selected with no lightmap.";
return 1;
}
if (doPrint || doExtract)
return !LightmapViewerHelpers::processLightmap(input, doPrint, doExtract);
}
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
LightmapFile *file = new LightmapFile();
if (!input.isEmpty())
file->setSource(QUrl::fromLocalFile(input));
file->loadData();
qmlRegisterSingletonInstance("LightmapFile", 1, 0, "LightmapFile", file);
LightmapImageProvider *provider = new LightmapImageProvider;
engine.addImageProvider(QLatin1String("lightmaps"), provider);
engine.loadFromModule("QtQuick3D.lightmapviewer", "LightmapViewer");
return app.exec();
}
|