Skip to content

Commit 2356a66

Browse files
committed
wasm: fix exporting
1 parent e29c18b commit 2356a66

File tree

7 files changed

+62
-22
lines changed

7 files changed

+62
-22
lines changed

application/SimpleHTTPServer_SharedArrayBuffer.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

application/sources/document_window.cc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,23 @@ void outputMessage(QtMsgType type, const QMessageLogContext& context, const QStr
6262
g_logBrowser->outputMessage(type, msg, context.file, context.line);
6363
}
6464

65-
void ensureFileExtension(QString* filename, const QString extension)
65+
void DocumentWindow::ensureFileExtension(QString* filename, const QString& extension)
6666
{
6767
if (!filename->endsWith(extension)) {
6868
filename->append(extension);
6969
}
7070
}
7171

72+
QString DocumentWindow::exportedFilename(const QString& filename, const QString& extension)
73+
{
74+
QString finalName = filename;
75+
if (!finalName.endsWith(extension))
76+
finalName += extension;
77+
if (finalName == extension)
78+
finalName = "Untitled" + finalName;
79+
return finalName;
80+
}
81+
7282
const std::map<DocumentWindow*, dust3d::Uuid>& DocumentWindow::documentWindows()
7383
{
7484
return g_documentWindows;
@@ -331,9 +341,12 @@ DocumentWindow::DocumentWindow()
331341
connect(m_exportAsGlbAction, &QAction::triggered, this, &DocumentWindow::exportGlbResult, Qt::QueuedConnection);
332342
m_fileMenu->addAction(m_exportAsGlbAction);
333343

344+
#if defined(Q_OS_WASM)
345+
#else
334346
m_exportAsFbxAction = new QAction(tr("Export as FBX..."), this);
335347
connect(m_exportAsFbxAction, &QAction::triggered, this, &DocumentWindow::exportFbxResult, Qt::QueuedConnection);
336348
m_fileMenu->addAction(m_exportAsFbxAction);
349+
#endif
337350

338351
m_fileMenu->addSeparator();
339352

@@ -875,7 +888,7 @@ void DocumentWindow::save()
875888
&snapshot,
876889
(!m_document->turnaround.isNull() && m_document->turnaroundPngByteArray.size() > 0) ? &m_document->turnaroundPngByteArray : nullptr)) {
877890
setCurrentFilename(m_currentFilename);
878-
QFileDialog::saveFileContent(fileContent);
891+
QFileDialog::saveFileContent(fileContent, exportedFilename(m_currentFilename, ".ds3"));
879892
}
880893
#else
881894
saveTo(m_currentFilename);
@@ -1074,13 +1087,25 @@ void DocumentWindow::open()
10741087

10751088
void DocumentWindow::exportObjResult()
10761089
{
1090+
#if defined(Q_OS_WASM)
1091+
QByteArray fileData;
1092+
QTextStream stream(&fileData);
1093+
ModelMesh* resultMesh = m_document->takeResultMesh();
1094+
if (nullptr != resultMesh) {
1095+
resultMesh->exportAsObj(&stream);
1096+
delete resultMesh;
1097+
}
1098+
stream.flush();
1099+
QFileDialog::saveFileContent(fileData, exportedFilename(m_currentFilename, ".obj"));
1100+
#else
10771101
QString filename = QFileDialog::getSaveFileName(this, QString(), QString(),
10781102
tr("Wavefront (*.obj)"));
10791103
if (filename.isEmpty()) {
10801104
return;
10811105
}
10821106
ensureFileExtension(&filename, ".obj");
10831107
exportObjToFilename(filename);
1108+
#endif
10841109
}
10851110

10861111
void DocumentWindow::exportObjToFilename(const QString& filename)
@@ -1126,13 +1151,31 @@ void DocumentWindow::exportFbxToFilename(const QString& filename)
11261151

11271152
void DocumentWindow::exportGlbResult()
11281153
{
1154+
#if defined(Q_OS_WASM)
1155+
if (!m_document->isExportReady())
1156+
return;
1157+
QByteArray fileData;
1158+
dust3d::Object skeletonResult = m_document->currentUvMappedObject();
1159+
QImage* textureMetalnessRoughnessAmbientOcclusionImage = UvMapGenerator::combineMetalnessRoughnessAmbientOcclusionImages(m_document->textureMetalnessImage,
1160+
m_document->textureRoughnessImage,
1161+
m_document->textureAmbientOcclusionImage);
1162+
GlbFileWriter glbFileWriter(skeletonResult, m_currentFilename + ".glb",
1163+
m_document->textureImage, m_document->textureNormalImage, textureMetalnessRoughnessAmbientOcclusionImage);
1164+
{
1165+
QDataStream stream(&fileData, QIODeviceBase::Append);
1166+
glbFileWriter.save(stream);
1167+
}
1168+
delete textureMetalnessRoughnessAmbientOcclusionImage;
1169+
QFileDialog::saveFileContent(fileData, exportedFilename(m_currentFilename, ".glb"));
1170+
#else
11291171
QString filename = QFileDialog::getSaveFileName(this, QString(), QString(),
11301172
tr("glTF Binary Format (*.glb)"));
11311173
if (filename.isEmpty()) {
11321174
return;
11331175
}
11341176
ensureFileExtension(&filename, ".glb");
11351177
exportGlbToFilename(filename);
1178+
#endif
11361179
}
11371180

11381181
void DocumentWindow::exportGlbToFilename(const QString& filename)

application/sources/document_window.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ public slots:
178178
SpinnableToolbarIcon* m_inprogressIndicator = nullptr;
179179

180180
std::map<QKeySequence, QShortcut*> m_shortcutMap;
181+
182+
private:
183+
static void ensureFileExtension(QString* filename, const QString& extension);
184+
static QString exportedFilename(const QString& filename, const QString& extension);
181185
};
182186

183187
#endif

application/sources/glb_file.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,8 @@ GlbFileWriter::GlbFileWriter(dust3d::Object& object,
278278
alignJson();
279279
}
280280

281-
bool GlbFileWriter::save()
281+
bool GlbFileWriter::save(QDataStream& output)
282282
{
283-
QFile file(m_filename);
284-
if (!file.open(QIODevice::WriteOnly)) {
285-
return false;
286-
}
287-
QDataStream output(&file);
288283
output.setFloatingPointPrecision(QDataStream::SinglePrecision);
289284
output.setByteOrder(QDataStream::LittleEndian);
290285

@@ -332,3 +327,13 @@ bool GlbFileWriter::save()
332327

333328
return true;
334329
}
330+
331+
bool GlbFileWriter::save()
332+
{
333+
QFile file(m_filename);
334+
if (!file.open(QIODevice::WriteOnly)) {
335+
return false;
336+
}
337+
QDataStream output(&file);
338+
return save(output);
339+
}

application/sources/glb_file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GlbFileWriter : public QObject {
2121
QImage* normalImage = nullptr,
2222
QImage* ormImage = nullptr);
2323
bool save();
24+
bool save(QDataStream& output);
2425

2526
private:
2627
QString m_filename;

application/sources/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char* argv[])
1616
QSurfaceFormat format;
1717
format.setDepthBufferSize(24);
1818
format.setAlphaBufferSize(8);
19-
format.setSamples(4);
19+
format.setSamples(8);
2020
QSurfaceFormat::setDefaultFormat(format);
2121

2222
//QSurfaceFormat format = QSurfaceFormat::defaultFormat();

application/sources/model_offscreen_render.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ QImage ModelOffscreenRender::toImage(const QSize& size)
101101
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
102102
format.setSamples(4);
103103
format.setTextureTarget(GL_TEXTURE_2D);
104-
//format.setInternalTextureFormat(GL_RGBA32F_ARB);
105104
m_renderFbo = new QOpenGLFramebufferObject(size, format);
106105
m_renderFbo->bind();
107106

0 commit comments

Comments
 (0)