1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QCoreApplication> |
5 | |
6 | #include <qlist.h> |
7 | |
8 | #include <QCommandLineOption> |
9 | #include <QCommandLineParser> |
10 | |
11 | #include <QtCore/qfile.h> |
12 | #include <QtCore/qdir.h> |
13 | |
14 | #include "shapemanager.h" |
15 | |
16 | int main(int argc, char *argv[]) |
17 | { |
18 | QCoreApplication app(argc, argv); |
19 | |
20 | QCommandLineParser cmdLineparser; |
21 | cmdLineparser.setApplicationDescription(QLatin1String("Tool to generate Qt Quick 3D Particles Custom Shapes" )); |
22 | cmdLineparser.addHelpOption(); |
23 | |
24 | QCommandLineOption imageOption({QChar(u'i'), QLatin1String("image" )}, QLatin1String("Input image for the data." ), QLatin1String("file" )); |
25 | cmdLineparser.addOption(commandLineOption: imageOption); |
26 | |
27 | QCommandLineOption outputOption({QChar(u'o'), QLatin1String("output" )}, QLatin1String("Output CBOR file for the shape data." ), QLatin1String("file" )); |
28 | cmdLineparser.addOption(commandLineOption: outputOption); |
29 | |
30 | QCommandLineOption depthOption({QChar(u'd'), QLatin1String("depth" )}, QLatin1String("Depth (z scale) for the data." ), QLatin1String("number" )); |
31 | cmdLineparser.addOption(commandLineOption: depthOption); |
32 | |
33 | QCommandLineOption scaleOption({QChar(u's'), QLatin1String("scale" )}, QLatin1String("Scale used for the image data. Default 1.0" ), QLatin1String("number" )); |
34 | cmdLineparser.addOption(commandLineOption: scaleOption); |
35 | |
36 | QCommandLineOption amountOption({QChar(u'a'), QLatin1String("amount" )}, QLatin1String("Amount of position data to generate." ), QLatin1String("number" )); |
37 | cmdLineparser.addOption(commandLineOption: amountOption); |
38 | |
39 | QCommandLineOption sortPositionOption({QChar(u'p'), QLatin1String("sorting-position" )}, QLatin1String("Position to use for sorting. Format \"x, y, z\"" ), QLatin1String("qvector3d" )); |
40 | cmdLineparser.addOption(commandLineOption: sortPositionOption); |
41 | |
42 | QCommandLineOption dumpCborFileOption({QChar(u'l'), QLatin1String("list-cbor" )}, QLatin1String("Lists CBOR file content." )); |
43 | cmdLineparser.addOption(commandLineOption: dumpCborFileOption); |
44 | |
45 | cmdLineparser.process(app); |
46 | |
47 | ShapeManager manager; |
48 | |
49 | if (!cmdLineparser.isSet(option: imageOption)) { |
50 | qWarning(msg: "Please provide the input image" ); |
51 | app.exit(retcode: -1); |
52 | return -1; |
53 | } else { |
54 | const auto imageFile = cmdLineparser.value(option: imageOption); |
55 | manager.setImage(imageFile); |
56 | } |
57 | |
58 | if (cmdLineparser.isSet(option: depthOption)) |
59 | manager.setDepth(cmdLineparser.value(option: depthOption).toFloat()); |
60 | |
61 | if (cmdLineparser.isSet(option: scaleOption)) |
62 | manager.setScale(cmdLineparser.value(option: scaleOption).toFloat()); |
63 | |
64 | if (cmdLineparser.isSet(option: amountOption)) |
65 | manager.setAmount(cmdLineparser.value(option: amountOption).toInt()); |
66 | |
67 | if (cmdLineparser.isSet(option: sortPositionOption)) { |
68 | QString posString = cmdLineparser.value(option: sortPositionOption); |
69 | QStringList list = posString.split(sep: QLatin1Char(',')); |
70 | QVector3D posVector; |
71 | if (list.size() > 0) |
72 | posVector.setX(list.at(i: 0).toFloat()); |
73 | if (list.size() > 1) |
74 | posVector.setY(list.at(i: 1).toFloat()); |
75 | if (list.size() > 2) |
76 | posVector.setZ(list.at(i: 2).toFloat()); |
77 | manager.setSortingPosition(posVector); |
78 | // TODO: Add command-line option |
79 | manager.setSortingMode(ShapeManager::SortingMode::DistanceClosestFirst); |
80 | } |
81 | |
82 | QString outputFile = "out.cbor" ; |
83 | if (cmdLineparser.isSet(option: outputOption)) |
84 | outputFile = cmdLineparser.value(option: outputOption); |
85 | |
86 | // Now generate data and store it in CBOR format |
87 | manager.generateData(); |
88 | manager.saveShapeData(filename: outputFile); |
89 | |
90 | if (cmdLineparser.isSet(option: dumpCborFileOption)) |
91 | manager.dumpOutput(); |
92 | |
93 | app.exit(retcode: 0); |
94 | return 0; |
95 | } |
96 | |