mirror of
https://github.com/overte-org/overte.git
synced 2025-08-14 09:32:03 +02:00
start on scripting interface to allow saving polyvox meshes to obj files
This commit is contained in:
parent
94537212f6
commit
541692c5ca
9 changed files with 175 additions and 1 deletions
|
@ -175,6 +175,7 @@
|
|||
#include <GPUIdent.h>
|
||||
#include <gl/GLHelpers.h>
|
||||
#include <EntityScriptClient.h>
|
||||
#include <ModelScriptingInterface.h>
|
||||
|
||||
// On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
|
||||
// FIXME seems to be broken.
|
||||
|
|
|
@ -71,6 +71,8 @@
|
|||
|
||||
#include <procedural/ProceduralSkybox.h>
|
||||
#include <model/Skybox.h>
|
||||
#include <ModelScriptingInterface.h>
|
||||
|
||||
|
||||
class OffscreenGLCanvas;
|
||||
class GLCanvas;
|
||||
|
|
|
@ -911,6 +911,10 @@ bool EntityScriptingInterface::setVoxelsInCuboid(QUuid entityID, const glm::vec3
|
|||
});
|
||||
}
|
||||
|
||||
MeshProxy* EntityScriptingInterface::voxelsToMesh(QUuid entityID) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {
|
||||
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
|
||||
if (!entity) {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "EntityItemProperties.h"
|
||||
|
||||
class EntityTree;
|
||||
class MeshProxy;
|
||||
|
||||
class RayToEntityIntersectionResult {
|
||||
public:
|
||||
|
@ -227,6 +228,7 @@ public slots:
|
|||
Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value);
|
||||
Q_INVOKABLE bool setVoxelsInCuboid(QUuid entityID, const glm::vec3& lowPosition,
|
||||
const glm::vec3& cuboidSize, int value);
|
||||
Q_INVOKABLE MeshProxy* voxelsToMesh(QUuid entityID);
|
||||
|
||||
Q_INVOKABLE bool setAllPoints(QUuid entityID, const QVector<glm::vec3>& points);
|
||||
Q_INVOKABLE bool appendPoint(QUuid entityID, const glm::vec3& point);
|
||||
|
|
71
libraries/fbx/src/OBJWriter.cpp
Normal file
71
libraries/fbx/src/OBJWriter.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
//
|
||||
// FBXReader.h
|
||||
// libraries/fbx/src/
|
||||
//
|
||||
// Created by Seth Alves on 2017-1-27.
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "OBJWriter.h"
|
||||
|
||||
|
||||
bool writeOBJ(QString outFileName, QVector<model::Mesh>) {
|
||||
//bool writeOBJ(QString outFileName, FBXGeometry& geometry, bool outputCentimeters, int whichMeshPart) {
|
||||
// QFile file(outFileName);
|
||||
// if (!file.open(QIODevice::WriteOnly)) {
|
||||
// qWarning() << "unable to write to" << outFileName;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// QTextStream out(&file);
|
||||
// if (outputCentimeters) {
|
||||
// out << "# This file uses centimeters as units\n\n";
|
||||
// }
|
||||
|
||||
// unsigned int nth = 0;
|
||||
|
||||
// // vertex indexes in obj files span the entire file
|
||||
// // vertex indexes in a mesh span just that mesh
|
||||
|
||||
// int vertexIndexOffset = 0;
|
||||
|
||||
// foreach (const FBXMesh& mesh, geometry.meshes) {
|
||||
// bool verticesHaveBeenOutput = false;
|
||||
// foreach (const FBXMeshPart &meshPart, mesh.parts) {
|
||||
// if (whichMeshPart >= 0 && nth != (unsigned int) whichMeshPart) {
|
||||
// nth++;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (!verticesHaveBeenOutput) {
|
||||
// for (int i = 0; i < mesh.vertices.size(); i++) {
|
||||
// glm::vec4 v = mesh.modelTransform * glm::vec4(mesh.vertices[i], 1.0f);
|
||||
// out << "v ";
|
||||
// out << formatFloat(v[0]) << " ";
|
||||
// out << formatFloat(v[1]) << " ";
|
||||
// out << formatFloat(v[2]) << "\n";
|
||||
// }
|
||||
// verticesHaveBeenOutput = true;
|
||||
// }
|
||||
|
||||
// out << "g hull-" << nth++ << "\n";
|
||||
// int triangleCount = meshPart.triangleIndices.size() / 3;
|
||||
// for (int i = 0; i < triangleCount; i++) {
|
||||
// out << "f ";
|
||||
// out << vertexIndexOffset + meshPart.triangleIndices[i*3] + 1 << " ";
|
||||
// out << vertexIndexOffset + meshPart.triangleIndices[i*3+1] + 1 << " ";
|
||||
// out << vertexIndexOffset + meshPart.triangleIndices[i*3+2] + 1 << "\n";
|
||||
// }
|
||||
// out << "\n";
|
||||
// }
|
||||
|
||||
// if (verticesHaveBeenOutput) {
|
||||
// vertexIndexOffset += mesh.vertices.size();
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
6
libraries/fbx/src/OBJWriter.h
Normal file
6
libraries/fbx/src/OBJWriter.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <model/Geometry.h>
|
||||
|
||||
bool writeOBJ(QString outFileName, QVector<model::Mesh>);
|
31
libraries/script-engine/src/ModelScriptingInterface.cpp
Normal file
31
libraries/script-engine/src/ModelScriptingInterface.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// ModelScriptingInterface.cpp
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Seth Alves on 2017-1-27.
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "ModelScriptingInterface.h"
|
||||
|
||||
ModelScriptingInterface::ModelScriptingInterface(QObject* parent) : QObject(parent) {
|
||||
}
|
||||
|
||||
|
||||
MeshProxy::MeshProxy(MeshPointer mesh) : _mesh(mesh) {
|
||||
}
|
||||
|
||||
MeshProxy::~MeshProxy() {
|
||||
}
|
||||
|
||||
|
||||
QScriptValue meshToScriptValue(QScriptEngine* engine, MeshProxy* const &in) {
|
||||
QScriptValue obj("something");
|
||||
return obj;
|
||||
}
|
||||
|
||||
void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out) {
|
||||
}
|
52
libraries/script-engine/src/ModelScriptingInterface.h
Normal file
52
libraries/script-engine/src/ModelScriptingInterface.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// ModelScriptingInterface.h
|
||||
// libraries/script-engine/src
|
||||
//
|
||||
// Created by Seth Alves on 2017-1-27.
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
#ifndef hifi_ModelScriptingInterface_h
|
||||
#define hifi_ModelScriptingInterface_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QScriptValue>
|
||||
#include <OBJWriter.h>
|
||||
#include <model/Geometry.h>
|
||||
|
||||
using MeshPointer = std::shared_ptr<model::Mesh>;
|
||||
|
||||
class ModelScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ModelScriptingInterface(QObject* parent);
|
||||
};
|
||||
|
||||
class MeshProxy : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MeshProxy(MeshPointer mesh);
|
||||
// MeshProxy(const MeshProxy& meshProxy) { _mesh = meshProxy.getMeshPointer(); }
|
||||
~MeshProxy();
|
||||
|
||||
MeshPointer getMeshPointer() const { return _mesh; }
|
||||
|
||||
protected:
|
||||
MeshPointer _mesh;
|
||||
};
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(MeshProxy*);
|
||||
|
||||
|
||||
QScriptValue meshToScriptValue(QScriptEngine* engine, MeshProxy* const &in);
|
||||
// QScriptValue meshToScriptValue(QScriptEngine* engine, const MeshPointer& in);
|
||||
void meshFromScriptValue(const QScriptValue& value, MeshProxy* &out);
|
||||
|
||||
#endif // hifi_ModelScriptingInterface_h
|
|
@ -63,6 +63,8 @@
|
|||
#include "RecordingScriptingInterface.h"
|
||||
#include "ScriptEngines.h"
|
||||
#include "TabletScriptingInterface.h"
|
||||
#include "ModelScriptingInterface.h"
|
||||
|
||||
|
||||
#include "MIDIEvent.h"
|
||||
|
||||
|
@ -570,7 +572,7 @@ void ScriptEngine::init() {
|
|||
registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
|
||||
|
||||
registerGlobalObject("File", new FileScriptingInterface(this));
|
||||
|
||||
|
||||
qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
|
||||
qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
|
||||
|
||||
|
@ -586,6 +588,9 @@ void ScriptEngine::init() {
|
|||
registerGlobalObject("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
|
||||
registerGlobalObject("Assets", &_assetScriptingInterface);
|
||||
registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
|
||||
|
||||
registerGlobalObject("Model", new ModelScriptingInterface(this));
|
||||
qScriptRegisterMetaType(this, meshToScriptValue, meshFromScriptValue);
|
||||
}
|
||||
|
||||
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
||||
|
|
Loading…
Reference in a new issue