@@ -62,13 +62,23 @@ void outputMessage(QtMsgType type, const QMessageLogContext& context, const QStr
62
62
g_logBrowser->outputMessage (type, msg, context.file , context.line );
63
63
}
64
64
65
- void ensureFileExtension (QString* filename, const QString extension)
65
+ void DocumentWindow:: ensureFileExtension (QString* filename, const QString& extension)
66
66
{
67
67
if (!filename->endsWith (extension)) {
68
68
filename->append (extension);
69
69
}
70
70
}
71
71
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
+
72
82
const std::map<DocumentWindow*, dust3d::Uuid>& DocumentWindow::documentWindows ()
73
83
{
74
84
return g_documentWindows;
@@ -331,9 +341,12 @@ DocumentWindow::DocumentWindow()
331
341
connect (m_exportAsGlbAction, &QAction::triggered, this , &DocumentWindow::exportGlbResult, Qt::QueuedConnection);
332
342
m_fileMenu->addAction (m_exportAsGlbAction);
333
343
344
+ #if defined(Q_OS_WASM)
345
+ #else
334
346
m_exportAsFbxAction = new QAction (tr (" Export as FBX..." ), this );
335
347
connect (m_exportAsFbxAction, &QAction::triggered, this , &DocumentWindow::exportFbxResult, Qt::QueuedConnection);
336
348
m_fileMenu->addAction (m_exportAsFbxAction);
349
+ #endif
337
350
338
351
m_fileMenu->addSeparator ();
339
352
@@ -875,7 +888,7 @@ void DocumentWindow::save()
875
888
&snapshot,
876
889
(!m_document->turnaround .isNull () && m_document->turnaroundPngByteArray .size () > 0 ) ? &m_document->turnaroundPngByteArray : nullptr )) {
877
890
setCurrentFilename (m_currentFilename);
878
- QFileDialog::saveFileContent (fileContent);
891
+ QFileDialog::saveFileContent (fileContent, exportedFilename (m_currentFilename, " .ds3 " ) );
879
892
}
880
893
#else
881
894
saveTo (m_currentFilename);
@@ -1074,13 +1087,25 @@ void DocumentWindow::open()
1074
1087
1075
1088
void DocumentWindow::exportObjResult ()
1076
1089
{
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
1077
1101
QString filename = QFileDialog::getSaveFileName (this , QString (), QString (),
1078
1102
tr (" Wavefront (*.obj)" ));
1079
1103
if (filename.isEmpty ()) {
1080
1104
return ;
1081
1105
}
1082
1106
ensureFileExtension (&filename, " .obj" );
1083
1107
exportObjToFilename (filename);
1108
+ #endif
1084
1109
}
1085
1110
1086
1111
void DocumentWindow::exportObjToFilename (const QString& filename)
@@ -1126,13 +1151,31 @@ void DocumentWindow::exportFbxToFilename(const QString& filename)
1126
1151
1127
1152
void DocumentWindow::exportGlbResult ()
1128
1153
{
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
1129
1171
QString filename = QFileDialog::getSaveFileName (this , QString (), QString (),
1130
1172
tr (" glTF Binary Format (*.glb)" ));
1131
1173
if (filename.isEmpty ()) {
1132
1174
return ;
1133
1175
}
1134
1176
ensureFileExtension (&filename, " .glb" );
1135
1177
exportGlbToFilename (filename);
1178
+ #endif
1136
1179
}
1137
1180
1138
1181
void DocumentWindow::exportGlbToFilename (const QString& filename)
0 commit comments