Skip to content

Commit

Permalink
filter sketchfab allows to save API code in MeshLab settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Aug 29, 2020
1 parent 3d98ec3 commit e243315
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/meshlabplugins/filter_sketchfab/filter_sketchfab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,25 @@ int FilterSketchFabPlugin::postCondition(QAction*) const

void FilterSketchFabPlugin::initParameterSet(QAction* action, MeshModel&, RichParameterList& parlst)
{
QSettings settings;
QVariant v = settings.value("SketchFab Code");
QString sketchFabAPIValue;
if (v == QVariant()) {
sketchFabAPIValue = DEFAULT_API;
}
else {
sketchFabAPIValue = v.toString();
}
switch(ID(action)) {
case FP_SKETCHFAB :
parlst.addParam(RichString("sketchFabKeyCode", "00000000", "Sketch Fab Code", "Mandatory."));
parlst.addParam(RichString("sketchFabKeyCode", sketchFabAPIValue, "Sketch Fab Code", "Mandatory."));
parlst.addParam(RichString("title", "MeshLabModel", "Title", "Mandatory."));
parlst.addParam(RichString("description", "A model generated with meshlab", "Description", "Mandatory. A short description of the model that is uploaded."));
parlst.addParam(RichString("tags", "meshlab", "Tags", "Mandatory. Tags must be separated by a space. Typical tags usually used by MeshLab users: scan, photogrammetry."));
parlst.addParam(RichBool("isPrivate", false, "Private", "This parameter can be true only for PRO account."));
parlst.addParam(RichBool("isPublished", false, "Publish", "If true the model will be published immediately."));
parlst.addParam(RichBool("autoRotate", true, "Auto Rotate", "If true the model rotated by 90 degree on the X axis to maintain similar default orientation."));
parlst.addParam(RichBool("saveApiSetting", sketchFabAPIValue != DEFAULT_API, "Save SketchFab Code", "Saves the API SketchFab code into the MeshLab settings, allowing to load it as default value every time you run this filter."));
break;
default :
assert(0);
Expand All @@ -120,7 +130,7 @@ bool FilterSketchFabPlugin::applyFilter(QAction * action, MeshDocument& md, cons
par.getString("sketchFabKeyCode"), par.getString("title"),
par.getString("description"), par.getString("tags"),
par.getBool("isPrivate"), par.getBool("isPublished"),
par.getBool("autoRotate"));
par.getBool("autoRotate"), par.getBool("saveApiSetting"));
default:
assert(0);
return false;
Expand All @@ -136,7 +146,8 @@ bool FilterSketchFabPlugin::sketchfab(
const QString& tags,
bool isPrivate,
bool isPublished,
bool /*autoRotate*/)
bool /*autoRotate*/,
bool saveApiSetting)
{
qDebug("Export to SketchFab start ");
this->fcb=cb;
Expand All @@ -145,11 +156,19 @@ bool FilterSketchFabPlugin::sketchfab(
Matrix44m rot; rot.SetRotateDeg(-90,Point3m(1,0,0));
Matrix44m rotI; rot.SetRotateDeg(90,Point3m(1,0,0));

if(apiToken.isEmpty() || apiToken=="0000000") {
if(apiToken.isEmpty() || apiToken == DEFAULT_API) {
this->errorMessage = QString("Please set in the MeshLab preferences your private API Token string that you can find on the<a href=\"https://sketchfab.com/settings/password\">Sketchfab Password Settings.");
return false;
}

QSettings settings;
if (saveApiSetting) {
settings.setValue("SketchFab Code", apiToken);
}
else {
settings.remove("SketchFab Code");
}

QString tmpObjFileName = QDir::tempPath() + "/xxxx.ply";
QString tmpZipFileName = QDir::tempPath() + "/xxxx.zip";

Expand Down
5 changes: 3 additions & 2 deletions src/meshlabplugins/filter_sketchfab/filter_sketchfab.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public slots:
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);

private:
bool sketchfab(
MeshDocument &md,
bool sketchfab(MeshDocument &md,
vcg::CallBackPos* cb,
const QString& apiToken,
const QString&,
const QString&,
const QString&,
bool,
bool,
bool,
bool);

bool upload(
Expand All @@ -83,6 +83,7 @@ public slots:

bool uploadCompleteFlag;
vcg::CallBackPos * fcb;
const QString DEFAULT_API = "00000000";

};

Expand Down
2 changes: 1 addition & 1 deletion vcglib

0 comments on commit e243315

Please sign in to comment.