Beginnings of some metavoxel scriptability, to create some test landscapes.

This commit is contained in:
Andrzej Kapolka 2014-07-14 14:32:55 -07:00
parent eab0fa4c27
commit e32bab5b04
5 changed files with 36 additions and 0 deletions

View file

@ -3641,6 +3641,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
scriptEngine->registerGlobalObject("AnimationCache", &_animationCache);
scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector);
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
#ifdef HAVE_RTMIDI
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());

View file

@ -14,6 +14,7 @@
#include <QCryptographicHash>
#include <QDataStream>
#include <QMetaType>
#include <QScriptEngine>
#include <QScriptValueIterator>
#include <QUrl>
#include <QtDebug>
@ -128,6 +129,12 @@ QList<const QMetaObject*> Bitstream::getMetaObjectSubClasses(const QMetaObject*
return getMetaObjectSubClasses().values(metaObject);
}
void Bitstream::configureScriptEngine(QScriptEngine* engine) {
foreach (const QMetaObject* metaObject, getMetaObjects()) {
engine->globalObject().setProperty(metaObject->className(), engine->newQMetaObject(metaObject));
}
}
Bitstream::Bitstream(QDataStream& underlying, MetadataType metadataType, GenericsMode genericsMode, QObject* parent) :
QObject(parent),
_underlying(underlying),

View file

@ -32,6 +32,7 @@
class QByteArray;
class QColor;
class QDataStream;
class QScriptEngine;
class QScriptValue;
class QUrl;
@ -320,6 +321,10 @@ public:
/// subclasses.
static QList<const QMetaObject*> getMetaObjectSubClasses(const QMetaObject* metaObject);
/// Configures the supplied script engine with our registered meta-objects, allowing all of them to be instantiated from
/// scripts.
static void configureScriptEngine(QScriptEngine* engine);
enum MetadataType { NO_METADATA, HASH_METADATA, FULL_METADATA };
enum GenericsMode { NO_GENERICS, FALLBACK_GENERICS, ALL_GENERICS };

View file

@ -9,6 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QThread>
#include "MetavoxelClientManager.h"
#include "MetavoxelMessages.h"
@ -53,7 +55,24 @@ SharedObjectPointer MetavoxelClientManager::findFirstRaySpannerIntersection(cons
return closestSpanner;
}
void MetavoxelClientManager::setSphere(const glm::vec3& center, float radius, QRgb color) {
Sphere* sphere = new Sphere();
sphere->setTranslation(center);
sphere->setScale(radius);
sphere->setColor(color);
setSpanner(sphere);
}
void MetavoxelClientManager::setSpanner(const SharedObjectPointer& object, bool reliable) {
MetavoxelEditMessage edit = { QVariant::fromValue(SetSpannerEdit(object)) };
applyEdit(edit, reliable);
}
void MetavoxelClientManager::applyEdit(const MetavoxelEditMessage& edit, bool reliable) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "applyEdit", Q_ARG(const MetavoxelEditMessage&, edit), Q_ARG(bool, reliable));
return;
}
foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
if (node->getType() == NodeType::MetavoxelServer) {
QMutexLocker locker(&node->getMutex());

View file

@ -28,6 +28,10 @@ public:
SharedObjectPointer findFirstRaySpannerIntersection(const glm::vec3& origin, const glm::vec3& direction,
const AttributePointer& attribute, float& distance);
Q_INVOKABLE void setSphere(const glm::vec3& center, float radius, QRgb color = 0x808080);
Q_INVOKABLE void setSpanner(const SharedObjectPointer& object, bool reliable = false);
Q_INVOKABLE void applyEdit(const MetavoxelEditMessage& edit, bool reliable = false);