mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-07 13:12:39 +02: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 "OBJWriter.h"
|
||||
|
||||
|
||||
|
||||
static QString formatFloat(double n) {
|
||||
// limit precision to 6, but don't output trailing zeros.
|
||||
QString s = QString::number(n, 'f', 6);
|
||||
|
@ -28,9 +26,7 @@ static QString formatFloat(double n) {
|
|||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes) {
|
||||
bool writeOBJToTextStream(QTextStream& out, QList<MeshPointer> meshes) {
|
||||
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,
|
||||
|
@ -110,8 +106,7 @@ bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool writeOBJToFile(QString path, MeshPointer mesh) {
|
||||
bool writeOBJToFile(QString path, QList<MeshPointer> meshes) {
|
||||
if (QFileInfo(path).exists() && !QFile::remove(path)) {
|
||||
qDebug() << "OBJ writer failed, file exists:" << path; // XXX qCDebug
|
||||
return false;
|
||||
|
@ -126,7 +121,6 @@ bool writeOBJToFile(QString path, MeshPointer mesh) {
|
|||
QTextStream outStream(&file);
|
||||
|
||||
bool success;
|
||||
std::vector<MeshPointer> meshes { mesh };
|
||||
success = writeOBJToTextStream(outStream, meshes);
|
||||
|
||||
file.close();
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <model/Geometry.h>
|
||||
|
||||
using MeshPointer = std::shared_ptr<model::Mesh>;
|
||||
|
||||
bool writeOBJToTextStream(QTextStream& out, std::vector<MeshPointer> meshes);
|
||||
bool writeOBJToFile(QString path, MeshPointer mesh);
|
||||
bool writeOBJToTextStream(QTextStream& out, QList<MeshPointer> meshes);
|
||||
bool writeOBJToFile(QString path, QList<MeshPointer> meshes);
|
||||
|
||||
|
||||
#endif // hifi_objwriter_h
|
||||
|
|
|
@ -33,7 +33,9 @@ protected:
|
|||
MeshPointer _mesh;
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
//
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QtScript/QScriptValue>
|
||||
#include "ModelScriptingInterface.h"
|
||||
#include "OBJWriter.h"
|
||||
|
@ -27,10 +28,31 @@ void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out) {
|
|||
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;
|
||||
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) {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -27,11 +27,13 @@ class ModelScriptingInterface : public QObject {
|
|||
public:
|
||||
ModelScriptingInterface(QObject* parent);
|
||||
|
||||
Q_INVOKABLE QString meshToOBJ(MeshProxy* const &in);
|
||||
Q_INVOKABLE QString meshToOBJ(MeshProxyList in);
|
||||
};
|
||||
|
||||
QScriptValue meshToScriptValue(QScriptEngine* engine, MeshProxy* const &in);
|
||||
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
|
||||
|
|
|
@ -591,6 +591,7 @@ void ScriptEngine::init() {
|
|||
|
||||
registerGlobalObject("Model", new ModelScriptingInterface(this));
|
||||
qScriptRegisterMetaType(this, meshToScriptValue, meshFromScriptValue);
|
||||
qScriptRegisterMetaType(this, meshesToScriptValue, meshesFromScriptValue);
|
||||
}
|
||||
|
||||
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
||||
|
|
Loading…
Reference in a new issue