Skip to content

Commit b9a600b

Browse files
committed
Add exporting passes to embed data in base64
It is now possible to choose whethere one wants to : - Embed everything in base64 - Extract every embedded thing - Keep things as they are This refactors GLTF2Exporter by separating in multiple passes
1 parent ee03832 commit b9a600b

36 files changed

+1774
-616
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ moc_*
2424
/.qmake.stash
2525
*.blend1
2626
config.tests/draco/.obj
27+
config.tests/draco/draco
28+

src/core/draco_prefix_p.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
This file is part of Kuesa.
55
6-
Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
6+
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
77
Author: Jean-Michaël Celerier <[email protected]>
88
99
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
copyingexportpass_cpp.h
3+
4+
This file is part of Kuesa.
5+
6+
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
7+
Author: Jean-Michaël Celerier <[email protected]>
8+
9+
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
10+
accordance with the Kuesa Enterprise License Agreement provided with the Software in the
11+
LICENSE.KUESA.ENTERPRISE file.
12+
13+
Contact [email protected] if any conditions of this licensing are not clear to you.
14+
15+
This program is free software: you can redistribute it and/or modify
16+
it under the terms of the GNU Affero General Public License as
17+
published by the Free Software Foundation, either version 3 of the
18+
License, or (at your option) any later version.
19+
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU Affero General Public License for more details.
24+
25+
You should have received a copy of the GNU Affero General Public License
26+
along with this program. If not, see <https://www.gnu.org/licenses/>.
27+
*/
28+
29+
#include "copyexportpass_p.h"
30+
#include "gltf2keys_p.h"
31+
#include "gltf2exporter_p.h"
32+
#include "gltf2uri_p.h"
33+
#include <QJsonArray>
34+
35+
QT_BEGIN_NAMESPACE
36+
namespace Kuesa {
37+
38+
/*!
39+
* \class CopyExportPass
40+
* \brief glTF export pass that copies referenced assets in another folder.
41+
*/
42+
CopyExportPass::CopyExportPass(const QDir &source, const QDir &destination)
43+
: m_basePath(source)
44+
, m_destination(destination)
45+
{
46+
}
47+
48+
void CopyExportPass::addGeneratedFiles(const QStringList &lst)
49+
{
50+
m_generated << lst;
51+
}
52+
53+
const QStringList &CopyExportPass::errors() const
54+
{
55+
return m_errors;
56+
}
57+
58+
void CopyExportPass::copyURIs(QJsonObject &root, QLatin1String key)
59+
{
60+
using namespace GLTF2Import;
61+
if (m_basePath == m_destination)
62+
return;
63+
64+
auto array_it = root.find(key);
65+
if (array_it == root.end())
66+
return;
67+
68+
const auto &array = array_it->toArray();
69+
for (const auto &val : array) {
70+
const auto &buffer = val.toObject();
71+
const auto uri_it = buffer.find(GLTF2Import::KEY_URI);
72+
if (uri_it == buffer.end())
73+
continue;
74+
75+
const auto uri = uri_it->toString();
76+
if (Uri::kind(uri) != Uri::Kind::Path)
77+
continue;
78+
79+
if (m_generated.contains(uri))
80+
continue;
81+
82+
QFile srcFile(Uri::localFile(uri_it->toString(), m_basePath));
83+
const QFileInfo destFile(m_destination, uri_it->toString());
84+
85+
if (srcFile.exists()) {
86+
// Copy files from the source to the target directory
87+
QDir{}.mkpath(destFile.absolutePath());
88+
89+
const bool ok = srcFile.copy(m_destination.absoluteFilePath(uri_it->toString()));
90+
if (!ok) {
91+
m_errors << QStringLiteral("Unable to copy %1").arg(uri_it->toString());
92+
}
93+
} else {
94+
m_errors << QStringLiteral("Tried to copy missing file %1").arg(uri_it->toString());
95+
}
96+
}
97+
98+
*array_it = array;
99+
}
100+
101+
} // namespace Kuesa
102+
QT_END_NAMESPACE
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
copyingexportpass_p.h
3+
4+
This file is part of Kuesa.
5+
6+
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
7+
Author: Jean-Michaël Celerier <[email protected]>
8+
9+
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
10+
accordance with the Kuesa Enterprise License Agreement provided with the Software in the
11+
LICENSE.KUESA.ENTERPRISE file.
12+
13+
Contact [email protected] if any conditions of this licensing are not clear to you.
14+
15+
This program is free software: you can redistribute it and/or modify
16+
it under the terms of the GNU Affero General Public License as
17+
published by the Free Software Foundation, either version 3 of the
18+
License, or (at your option) any later version.
19+
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU Affero General Public License for more details.
24+
25+
You should have received a copy of the GNU Affero General Public License
26+
along with this program. If not, see <https://www.gnu.org/licenses/>.
27+
*/
28+
29+
#ifndef KUESA_GLTF2EXPORTER_COPYINGEXPORTPASS_P_H
30+
#define KUESA_GLTF2EXPORTER_COPYINGEXPORTPASS_P_H
31+
32+
//
33+
// NOTICE
34+
// ------
35+
//
36+
// We mean it: this file is not part of the public API and could be
37+
// modified without notice
38+
//
39+
40+
#include <QDir>
41+
#include <QStringList>
42+
#include <QJsonObject>
43+
44+
QT_BEGIN_NAMESPACE
45+
namespace Kuesa {
46+
47+
class CopyExportPass
48+
{
49+
public:
50+
CopyExportPass(
51+
const QDir &source,
52+
const QDir &destination);
53+
54+
void addGeneratedFiles(const QStringList &lst);
55+
const QStringList &errors() const;
56+
void copyURIs(QJsonObject &root, QLatin1String key);
57+
58+
private:
59+
QStringList m_errors;
60+
QStringList m_generated;
61+
QDir m_basePath, m_destination;
62+
};
63+
} // namespace Kuesa
64+
QT_END_NAMESPACE
65+
#endif // KUESA_GLTF2EXPORTER_COPYINGEXPORTPASS_P_H

src/core/gltf2exporter/dracocompressor_p.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
This file is part of Kuesa.
55
6-
Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
6+
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
77
Author: Juan Jose Casafranca <[email protected]>
88
99
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in
@@ -171,7 +171,7 @@ std::pair<QString, int> addAttributeToMesh(const Qt3DRender::QAttribute &attribu
171171
draco::PointAttribute meshAttribute;
172172
meshAttribute.Init(attributeTypeFromName(attribute.name()),
173173
nullptr,
174-
static_cast<int8_t>(attribute.vertexSize()),
174+
static_cast<qint8>(attribute.vertexSize()),
175175
dracoDataType,
176176
false,
177177
actualStride<T>(attribute.byteStride(), attribute.vertexSize()),
@@ -216,7 +216,7 @@ template<typename T>
216216
bool compressAttribute(
217217
const Qt3DRender::QAttribute &attribute,
218218
draco::Mesh &dracoMesh,
219-
std::vector<std::pair<QString, int>>& attributes)
219+
std::vector<std::pair<QString, int>> &attributes)
220220
{
221221
auto compressedAttr = addAttributeToMesh<T>(attribute, dracoMesh);
222222
if (compressedAttr.second == -1) {
@@ -273,43 +273,43 @@ CompressedMesh compressMesh(
273273

274274
switch (attribute->vertexBaseType()) {
275275
case Qt3DRender::QAttribute::VertexBaseType::Float: {
276-
if(!compressAttribute<float>(*attribute, dracoMesh, attributes))
276+
if (!compressAttribute<float>(*attribute, dracoMesh, attributes))
277277
return {};
278278
break;
279279
}
280280
case Qt3DRender::QAttribute::VertexBaseType::Byte: {
281281
static_assert (std::numeric_limits<qint8>::min() < 0, "This code only works on platforms with signed char");
282-
if(!compressAttribute<qint8>(*attribute, dracoMesh, attributes))
282+
if (!compressAttribute<qint8>(*attribute, dracoMesh, attributes))
283283
return {};
284284
break;
285285
}
286286
case Qt3DRender::QAttribute::VertexBaseType::UnsignedByte: {
287-
if(!compressAttribute<quint8>(*attribute, dracoMesh, attributes))
287+
if (!compressAttribute<quint8>(*attribute, dracoMesh, attributes))
288288
return {};
289289
break;
290290
}
291291
case Qt3DRender::QAttribute::VertexBaseType::Short: {
292-
if(!compressAttribute<qint16>(*attribute, dracoMesh, attributes))
292+
if (!compressAttribute<qint16>(*attribute, dracoMesh, attributes))
293293
return {};
294294
break;
295295
}
296296
case Qt3DRender::QAttribute::VertexBaseType::UnsignedShort: {
297-
if(!compressAttribute<quint16>(*attribute, dracoMesh, attributes))
297+
if (!compressAttribute<quint16>(*attribute, dracoMesh, attributes))
298298
return {};
299299
break;
300300
}
301301
case Qt3DRender::QAttribute::VertexBaseType::Int: {
302-
if(!compressAttribute<qint32>(*attribute, dracoMesh, attributes))
302+
if (!compressAttribute<qint32>(*attribute, dracoMesh, attributes))
303303
return {};
304304
break;
305305
}
306306
case Qt3DRender::QAttribute::VertexBaseType::UnsignedInt: {
307-
if(!compressAttribute<quint32>(*attribute, dracoMesh, attributes))
307+
if (!compressAttribute<quint32>(*attribute, dracoMesh, attributes))
308308
return {};
309309
break;
310310
}
311311
case Qt3DRender::QAttribute::VertexBaseType::Double: {
312-
if(!compressAttribute<double>(*attribute, dracoMesh, attributes))
312+
if (!compressAttribute<double>(*attribute, dracoMesh, attributes))
313313
return {};
314314
break;
315315
}

src/core/gltf2exporter/dracocompressor_p.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
This file is part of Kuesa.
55
6-
Copyright (C) 2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
6+
Copyright (C) 2018-2019 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
77
Author: Juan Jose Casafranca <[email protected]>
88
99
Licensees holding valid proprietary KDAB Kuesa licenses may use this file in

0 commit comments

Comments
 (0)