1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtQuick3D/private/qquick3dinstancing_p.h> |
5 | |
6 | extern void qt_writeInstanceTable(QIODevice *out, QQuick3DInstancing &instanceTable); |
7 | |
8 | int main(int argc, char **argv) |
9 | { |
10 | QQuick3DFileInstancing instanceTable; |
11 | if (argc < 2 || argc > 3) { |
12 | fprintf(stderr, format: "Usage: %s INFILE [OUTFILE]\n" , argv[0]); |
13 | return -1; |
14 | } |
15 | QString inFilename = QString::fromLocal8Bit(ba: argv[1]); |
16 | if (!instanceTable.loadFromXmlFile(filename: inFilename)) { |
17 | fprintf(stderr, format: "Could not read instance table %s\n" , argv[1]); |
18 | return -2; |
19 | } |
20 | |
21 | QString outFilename = argc > 2 ? QString::fromLocal8Bit(ba: argv[2]) : inFilename + QStringLiteral(".bin" ); |
22 | QFile outFile(outFilename); |
23 | if (!outFile.open(flags: QFile::WriteOnly)) { |
24 | fprintf(stderr, format: "Could not open %s for writing.\n" , qPrintable(outFilename)); |
25 | return -2; |
26 | } |
27 | |
28 | int instanceCount = instanceTable.writeToBinaryFile(out: &outFile); |
29 | |
30 | outFile.close(); |
31 | |
32 | if (instanceCount < 0) { |
33 | fprintf(stderr, format: "Could not write instance table.\n" ); |
34 | return -3; |
35 | } |
36 | |
37 | fprintf(stderr, format: "Wrote %d instances to %s.\n" , instanceCount, qPrintable(outFilename)); |
38 | |
39 | return 0; |
40 | } |
41 | |