mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
ModelScriptingInterface::meshToOBJ takes a list of MeshProxys instead of just one
This commit is contained in:
parent
9e8fcc0def
commit
91e542a7a7
6 changed files with 36 additions and 15 deletions
|
@ -14,8 +14,6 @@
|
||||||
#include "model/Geometry.h"
|
#include "model/Geometry.h"
|
||||||
#include "OBJWriter.h"
|
#include "OBJWriter.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QString formatFloat(double n) {
|
static QString formatFloat(double n) {
|
||||||
// limit precision to 6, but don't output trailing zeros.
|
// limit precision to 6, but don't output trailing zeros.
|
||||||
QString s = QString::number(n, 'f', 6);
|
QString s = QString::number(n, 'f', 6);
|
||||||
|
@ -28,9 +26,7 @@ static QString formatFloat(double n) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeOBJToTextStream(QTextStream& out, QList<MeshPointer> meshes) {
|
||||||
|
|
||||||
bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes) {
|
|
||||||
qDebug() << "writeOBJToTextStream mesh count is" << meshes.size();
|
qDebug() << "writeOBJToTextStream mesh count is" << meshes.size();
|
||||||
|
|
||||||
// each mesh's vertices are numbered from zero. We're combining all their vertices into one list here,
|
// each mesh's vertices are numbered from zero. We're combining all their vertices into one list here,
|
||||||
|
@ -110,8 +106,7 @@ bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeOBJToFile(QString path, QList<MeshPointer> meshes) {
|
||||||
bool writeOBJToFile(QString path, MeshPointer mesh) {
|
|
||||||
if (QFileInfo(path).exists() && !QFile::remove(path)) {
|
if (QFileInfo(path).exists() && !QFile::remove(path)) {
|
||||||
qDebug() << "OBJ writer failed, file exists:" << path; // XXX qCDebug
|
qDebug() << "OBJ writer failed, file exists:" << path; // XXX qCDebug
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,7 +121,6 @@ bool writeOBJToFile(QString path, MeshPointer mesh) {
|
||||||
QTextStream outStream(&file);
|
QTextStream outStream(&file);
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
std::vector<MeshPointer> meshes { mesh };
|
|
||||||
success = writeOBJToTextStream(outStream, meshes);
|
success = writeOBJToTextStream(outStream, meshes);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
|
@ -14,13 +14,13 @@
|
||||||
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QList>
|
||||||
#include <model/Geometry.h>
|
#include <model/Geometry.h>
|
||||||
|
|
||||||
using MeshPointer = std::shared_ptr<model::Mesh>;
|
using MeshPointer = std::shared_ptr<model::Mesh>;
|
||||||
|
|
||||||
bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes);
|
bool writeOBJToTextStream(QTextStream& out, QList<MeshPointer> meshes);
|
||||||
bool writeOBJToFile(QString path, MeshPointer mesh);
|
bool writeOBJToFile(QString path, QList<MeshPointer> meshes);
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_objwriter_h
|
#endif // hifi_objwriter_h
|
||||||
|
|
|
@ -33,7 +33,9 @@ protected:
|
||||||
MeshPointer _mesh;
|
MeshPointer _mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(MeshProxy*);
|
Q_DECLARE_METATYPE(MeshProxy*);
|
||||||
|
|
||||||
|
class MeshProxyList : public QList<MeshProxy*> {}; // typedef and using fight with the Qt macros/templates, do this instead
|
||||||
|
Q_DECLARE_METATYPE(MeshProxyList);
|
||||||
|
|
||||||
#endif // hifi_MeshProxy_h
|
#endif // hifi_MeshProxy_h
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
|
#include <QScriptValueIterator>
|
||||||
#include <QtScript/QScriptValue>
|
#include <QtScript/QScriptValue>
|
||||||
#include "ModelScriptingInterface.h"
|
#include "ModelScriptingInterface.h"
|
||||||
#include "OBJWriter.h"
|
#include "OBJWriter.h"
|
||||||
|
@ -27,10 +28,31 @@ void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out) {
|
||||||
out = qobject_cast<MeshProxy*>(value.toQObject());
|
out = qobject_cast<MeshProxy*>(value.toQObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ModelScriptingInterface::meshToOBJ(MeshProxy* const &in) {
|
QScriptValue meshesToScriptValue(QScriptEngine* engine, const MeshProxyList &in) {
|
||||||
|
return engine->toScriptValue(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
void meshesFromScriptValue(const QScriptValue& value, MeshProxyList &out) {
|
||||||
|
QScriptValueIterator itr(value);
|
||||||
|
while(itr.hasNext()) {
|
||||||
|
itr.next();
|
||||||
|
MeshProxy* meshProxy = qscriptvalue_cast<MeshProxyList::value_type>(itr.value());
|
||||||
|
if (meshProxy) {
|
||||||
|
out.append(meshProxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ModelScriptingInterface::meshToOBJ(MeshProxyList in) {
|
||||||
bool success;
|
bool success;
|
||||||
QString filename = "/tmp/okokok.obj";
|
QString filename = "/tmp/okokok.obj";
|
||||||
success = writeOBJToFile(filename, in->getMeshPointer());
|
|
||||||
|
QList<MeshPointer> meshes;
|
||||||
|
foreach (const MeshProxy* meshProxy, in) {
|
||||||
|
meshes.append(meshProxy->getMeshPointer());
|
||||||
|
}
|
||||||
|
|
||||||
|
success = writeOBJToFile(filename, meshes);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,13 @@ class ModelScriptingInterface : public QObject {
|
||||||
public:
|
public:
|
||||||
ModelScriptingInterface(QObject* parent);
|
ModelScriptingInterface(QObject* parent);
|
||||||
|
|
||||||
Q_INVOKABLE QString meshToOBJ(MeshProxy* const &in);
|
Q_INVOKABLE QString meshToOBJ(MeshProxyList in);
|
||||||
};
|
};
|
||||||
|
|
||||||
QScriptValue meshToScriptValue(QScriptEngine* engine, MeshProxy* const &in);
|
QScriptValue meshToScriptValue(QScriptEngine* engine, MeshProxy* const &in);
|
||||||
void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out);
|
void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out);
|
||||||
|
|
||||||
|
QScriptValue meshesToScriptValue(QScriptEngine* engine, const MeshProxyList &in);
|
||||||
|
void meshesFromScriptValue(const QScriptValue& value, MeshProxyList &out);
|
||||||
|
|
||||||
#endif // hifi_ModelScriptingInterface_h
|
#endif // hifi_ModelScriptingInterface_h
|
||||||
|
|
|
@ -591,6 +591,7 @@ void ScriptEngine::init() {
|
||||||
|
|
||||||
registerGlobalObject("Model", new ModelScriptingInterface(this));
|
registerGlobalObject("Model", new ModelScriptingInterface(this));
|
||||||
qScriptRegisterMetaType(this, meshToScriptValue, meshFromScriptValue);
|
qScriptRegisterMetaType(this, meshToScriptValue, meshFromScriptValue);
|
||||||
|
qScriptRegisterMetaType(this, meshesToScriptValue, meshesFromScriptValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
||||||
|
|
Loading…
Reference in a new issue