mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #3784 from ctrlaltdavid/20157
CR for Job #20157 - Enable "Get Overlay properties" from javascript
This commit is contained in:
commit
27c37f3a4e
34 changed files with 429 additions and 5 deletions
|
@ -167,6 +167,48 @@ var clipboardPreview = Overlays.addOverlay("clipboard", {
|
|||
visible: true
|
||||
});
|
||||
|
||||
// Demonstrate retrieving overlay properties
|
||||
print("Text overlay text property value =\n" + Overlays.getProperty(text, "text"));
|
||||
print("Text overlay alpha =\n" + Overlays.getProperty(text, "alpha"));
|
||||
print("Text overlay visible =\n" + Overlays.getProperty(text, "visible"));
|
||||
print("Text overlay font size =\n" + Overlays.getProperty(text, "font").size);
|
||||
print("Text overlay anchor =\n" + Overlays.getProperty(text, "anchor"));
|
||||
print("Text overlay unknown property value =\n" + Overlays.getProperty(text, "unknown")); // value = undefined
|
||||
var sliderBounds = Overlays.getProperty(slider, "bounds");
|
||||
print("Slider overlay bounds =\n"
|
||||
+ "x: " + sliderBounds.x + "\n"
|
||||
+ "y: " + sliderBounds.y + "\n"
|
||||
+ "width: " + sliderBounds.width + "\n"
|
||||
+ "height: " + sliderBounds.height
|
||||
);
|
||||
|
||||
var cubePosition = Overlays.getProperty(cube, "position");
|
||||
print("Cube overlay position =\n"
|
||||
+ "x: " + cubePosition.x + "\n"
|
||||
+ "y: " + cubePosition.y + "\n"
|
||||
+ "z: " + cubePosition.z
|
||||
);
|
||||
var cubeColor = Overlays.getProperty(cube, "color");
|
||||
print("Cube overlay color =\n"
|
||||
+ "red: " + cubeColor.red + "\n"
|
||||
+ "green: " + cubeColor.green + "\n"
|
||||
+ "blue: " + cubeColor.blue
|
||||
);
|
||||
var modelOverlayProperties = {
|
||||
textures: {
|
||||
filename1: "http://url1",
|
||||
filename2: "http://url2"
|
||||
}
|
||||
}
|
||||
var modelOverlay = Overlays.addOverlay("model", modelOverlayProperties);
|
||||
var textures = Overlays.getProperty(modelOverlay, "textures");
|
||||
var textureValues = "";
|
||||
for (key in textures) {
|
||||
textureValues += "\n" + key + ": " + textures[key];
|
||||
}
|
||||
print("Model overlay textures =" + textureValues);
|
||||
Overlays.deleteOverlay(modelOverlay);
|
||||
print("Unknown overlay property =\n" + Overlays.getProperty(1000, "text")); // value = undefined
|
||||
|
||||
// When our script shuts down, we should clean up all of our overlays
|
||||
function scriptEnding() {
|
||||
|
|
|
@ -3902,7 +3902,9 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));
|
||||
|
||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
||||
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue);
|
||||
qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
|
||||
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
|
||||
RayToOverlayIntersectionResultFromScriptValue);
|
||||
|
||||
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
|
||||
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
|
||||
|
|
|
@ -118,6 +118,32 @@ void Base3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue Base3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "position" || property == "start" || property == "p1" || property == "point") {
|
||||
return vec3toScriptValue(_scriptEngine, _position);
|
||||
}
|
||||
if (property == "lineWidth") {
|
||||
return _lineWidth;
|
||||
}
|
||||
if (property == "rotation") {
|
||||
return quatToScriptValue(_scriptEngine, _rotation);
|
||||
}
|
||||
if (property == "isSolid" || property == "isFilled" || property == "solid" || property == "filed") {
|
||||
return _isSolid;
|
||||
}
|
||||
if (property == "isWire" || property == "wire") {
|
||||
return !_isSolid;
|
||||
}
|
||||
if (property == "isDashedLine" || property == "dashed") {
|
||||
return _isDashedLine;
|
||||
}
|
||||
if (property == "ignoreRayIntersection") {
|
||||
return _ignoreRayIntersection;
|
||||
}
|
||||
|
||||
return Overlay::getProperty(property);
|
||||
}
|
||||
|
||||
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
return false;
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void setIgnoreRayIntersection(bool value) { _ignoreRayIntersection = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
|
||||
|
|
|
@ -157,6 +157,23 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue BillboardOverlay::getProperty(const QString& property) {
|
||||
if (property == "url") {
|
||||
return _url;
|
||||
}
|
||||
if (property == "subImage") {
|
||||
return qRectToScriptValue(_scriptEngine, _fromImage);
|
||||
}
|
||||
if (property == "scale") {
|
||||
return _scale;
|
||||
}
|
||||
if (property == "isFacingAvatar") {
|
||||
return _isFacingAvatar;
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
void BillboardOverlay::setURL(const QString& url) {
|
||||
setBillboardURL(url);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
|
||||
|
|
|
@ -299,6 +299,45 @@ void Circle3DOverlay::setProperties(const QScriptValue &properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue Circle3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "startAt") {
|
||||
return _startAt;
|
||||
}
|
||||
if (property == "endAt") {
|
||||
return _endAt;
|
||||
}
|
||||
if (property == "outerRadius") {
|
||||
return _outerRadius;
|
||||
}
|
||||
if (property == "innerRadius") {
|
||||
return _innerRadius;
|
||||
}
|
||||
if (property == "hasTickMarks") {
|
||||
return _hasTickMarks;
|
||||
}
|
||||
if (property == "majorTickMarksAngle") {
|
||||
return _majorTickMarksAngle;
|
||||
}
|
||||
if (property == "minorTickMarksAngle") {
|
||||
return _minorTickMarksAngle;
|
||||
}
|
||||
if (property == "majorTickMarksLength") {
|
||||
return _majorTickMarksLength;
|
||||
}
|
||||
if (property == "minorTickMarksLength") {
|
||||
return _minorTickMarksLength;
|
||||
}
|
||||
if (property == "majorTickMarksColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _majorTickMarksColor);
|
||||
}
|
||||
if (property == "minorTickMarksColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _minorTickMarksColor);
|
||||
}
|
||||
|
||||
return Planar3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
|
||||
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||
const glm::vec3& direction, float& distance, BoxFace& face) const {
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
~Circle3DOverlay();
|
||||
virtual void render(RenderArgs* args);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
float getStartAt() const { return _startAt; }
|
||||
float getEndAt() const { return _endAt; }
|
||||
|
|
|
@ -116,3 +116,14 @@ void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
_majorGridEvery = properties.property("majorGridEvery").toVariant().toInt();
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue Grid3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "minorGridWidth") {
|
||||
return _minorGridWidth;
|
||||
}
|
||||
if (property == "majorGridEvery") {
|
||||
return _majorGridEvery;
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
|
||||
virtual void render(RenderArgs* args);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
private:
|
||||
float _minorGridWidth;
|
||||
|
|
|
@ -151,4 +151,13 @@ void ImageOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue ImageOverlay::getProperty(const QString& property) {
|
||||
if (property == "subImage") {
|
||||
return qRectToScriptValue(_scriptEngine, _fromImage);
|
||||
}
|
||||
if (property == "imageURL") {
|
||||
return _imageURL.toString();
|
||||
}
|
||||
|
||||
return Overlay2D::getProperty(property);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; _wantClipFromImage = true; }
|
||||
void setImageURL(const QUrl& url);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
private slots:
|
||||
void replyFinished(); // we actually want to hide this...
|
||||
|
|
|
@ -79,3 +79,11 @@ void Line3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue Line3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "end" || property == "endPoint" || property == "p2") {
|
||||
return vec3toScriptValue(_scriptEngine, _end);
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
void setEnd(const glm::vec3& end) { _end = end; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
protected:
|
||||
glm::vec3 _end;
|
||||
|
|
|
@ -103,3 +103,14 @@ void LocalVoxelsOverlay::setProperties(const QScriptValue &properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue LocalVoxelsOverlay::getProperty(const QString& property) {
|
||||
if (property == "scale") {
|
||||
return vec3toScriptValue(_scriptEngine, getDimensions());
|
||||
}
|
||||
if (property == "name") {
|
||||
return _treeName;
|
||||
}
|
||||
|
||||
return Volume3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ public:
|
|||
virtual void render(RenderArgs* args);
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
private:
|
||||
static QMap<QString, WeakVoxelSystemPointer> _voxelSystemMap; // treeName/voxelSystem
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
ModelOverlay::ModelOverlay()
|
||||
: _model(),
|
||||
_modelTextures(QVariantMap()),
|
||||
_scale(1.0f),
|
||||
_updateModel(false)
|
||||
{
|
||||
|
@ -114,6 +115,8 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
|
|||
QMetaObject::invokeMethod(&_model, "setTextureWithNameToURL", Qt::AutoConnection,
|
||||
Q_ARG(const QString&, key),
|
||||
Q_ARG(const QUrl&, newTextureURL));
|
||||
|
||||
_modelTextures[key] = newTextureURL; // Keep local track of textures for getProperty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +125,34 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue ModelOverlay::getProperty(const QString& property) {
|
||||
if (property == "url") {
|
||||
return _url.toString();
|
||||
}
|
||||
if (property == "scale") {
|
||||
return _scale;
|
||||
}
|
||||
if (property == "rotation") {
|
||||
return quatToScriptValue(_scriptEngine, _rotation);
|
||||
}
|
||||
if (property == "dimensions") {
|
||||
return vec3toScriptValue(_scriptEngine, _model.getScaleToFitDimensions());
|
||||
}
|
||||
if (property == "textures") {
|
||||
if (_modelTextures.size() > 0) {
|
||||
QScriptValue textures = _scriptEngine->newObject();
|
||||
foreach(const QString& key, _modelTextures.keys()) {
|
||||
textures.setProperty(key, _modelTextures[key].toString());
|
||||
}
|
||||
return textures;
|
||||
} else {
|
||||
return QScriptValue();
|
||||
}
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
virtual void update(float deltatime);
|
||||
virtual void render(RenderArgs* args);
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||
|
@ -31,6 +32,7 @@ public:
|
|||
private:
|
||||
|
||||
Model _model;
|
||||
QVariantMap _modelTextures;
|
||||
|
||||
QUrl _url;
|
||||
glm::quat _rotation;
|
||||
|
|
|
@ -39,8 +39,9 @@ Overlay::Overlay() :
|
|||
{
|
||||
}
|
||||
|
||||
void Overlay::init(QGLWidget* parent) {
|
||||
void Overlay::init(QGLWidget* parent, QScriptEngine* scriptEngine) {
|
||||
_parent = parent;
|
||||
_scriptEngine = scriptEngine;
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,6 +105,44 @@ void Overlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue Overlay::getProperty(const QString& property) {
|
||||
if (property == "color") {
|
||||
return xColorToScriptValue(_scriptEngine, _color);
|
||||
}
|
||||
if (property == "alpha") {
|
||||
return _alpha;
|
||||
}
|
||||
if (property == "glowLevel") {
|
||||
return _glowLevel;
|
||||
}
|
||||
if (property == "pulseMax") {
|
||||
return _pulseMax;
|
||||
}
|
||||
if (property == "pulseMin") {
|
||||
return _pulseMin;
|
||||
}
|
||||
if (property == "pulsePeriod") {
|
||||
return _pulsePeriod;
|
||||
}
|
||||
if (property == "glowLevelPulse") {
|
||||
return _glowLevelPulse;
|
||||
}
|
||||
if (property == "alphaPulse") {
|
||||
return _alphaPulse;
|
||||
}
|
||||
if (property == "colorPulse") {
|
||||
return _colorPulse;
|
||||
}
|
||||
if (property == "visible") {
|
||||
return _visible;
|
||||
}
|
||||
if (property == "anchor") {
|
||||
return _anchor == MY_AVATAR ? "MyAvatar" : "";
|
||||
}
|
||||
|
||||
return QScriptValue();
|
||||
}
|
||||
|
||||
xColor Overlay::getColor() {
|
||||
if (_colorPulse == 0.0f) {
|
||||
return _color;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <QScriptValue>
|
||||
#include <QString>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include <SharedUtil.h> // for xColor
|
||||
#include <RenderArgs.h>
|
||||
|
||||
|
@ -36,7 +37,7 @@ public:
|
|||
|
||||
Overlay();
|
||||
~Overlay();
|
||||
void init(QGLWidget* parent);
|
||||
void init(QGLWidget* parent, QScriptEngine* scriptEngine);
|
||||
virtual void update(float deltatime) {}
|
||||
virtual void render(RenderArgs* args) = 0;
|
||||
|
||||
|
@ -77,6 +78,7 @@ public:
|
|||
void setAlphaPulse(float value) { _alphaPulse = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
protected:
|
||||
float updatePulse();
|
||||
|
@ -100,6 +102,8 @@ protected:
|
|||
xColor _color;
|
||||
bool _visible; // should the overlay be drawn at all
|
||||
Anchor _anchor;
|
||||
|
||||
QScriptEngine* _scriptEngine;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -64,3 +64,23 @@ void Overlay2D::setProperties(const QScriptValue& properties) {
|
|||
//qDebug() << "set bounds to " << getBounds();
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue Overlay2D::getProperty(const QString& property) {
|
||||
if (property == "bounds") {
|
||||
return qRectToScriptValue(_scriptEngine, _bounds);
|
||||
}
|
||||
if (property == "x") {
|
||||
return _bounds.x();
|
||||
}
|
||||
if (property == "y") {
|
||||
return _bounds.y();
|
||||
}
|
||||
if (property == "width") {
|
||||
return _bounds.width();
|
||||
}
|
||||
if (property == "height") {
|
||||
return _bounds.height();
|
||||
}
|
||||
|
||||
return Overlay::getProperty(property);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
void setBounds(const QRect& bounds) { _bounds = bounds; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
protected:
|
||||
QRect _bounds; // where on the screen to draw
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <typeinfo>
|
||||
#include <Application.h>
|
||||
#include <Menu.h>
|
||||
#include <QScriptValueIterator>
|
||||
|
||||
#include "BillboardOverlay.h"
|
||||
#include "Circle3DOverlay.h"
|
||||
|
@ -56,6 +57,7 @@ Overlays::~Overlays() {
|
|||
|
||||
void Overlays::init(QGLWidget* parent) {
|
||||
_parent = parent;
|
||||
_scriptEngine = new QScriptEngine();
|
||||
}
|
||||
|
||||
void Overlays::update(float deltatime) {
|
||||
|
@ -180,7 +182,7 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
|
|||
}
|
||||
|
||||
unsigned int Overlays::addOverlay(Overlay* overlay) {
|
||||
overlay->init(_parent);
|
||||
overlay->init(_parent, _scriptEngine);
|
||||
|
||||
QWriteLocker lock(&_lock);
|
||||
unsigned int thisID = _nextOverlayID;
|
||||
|
@ -242,6 +244,51 @@ unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) {
|
|||
return 0; // not found
|
||||
}
|
||||
|
||||
OverlayPropertyResult Overlays::getProperty(unsigned int id, const QString& property) {
|
||||
OverlayPropertyResult result;
|
||||
Overlay* thisOverlay = NULL;
|
||||
QReadLocker lock(&_lock);
|
||||
if (_overlays2D.contains(id)) {
|
||||
thisOverlay = _overlays2D[id];
|
||||
} else if (_overlays3D.contains(id)) {
|
||||
thisOverlay = _overlays3D[id];
|
||||
}
|
||||
if (thisOverlay) {
|
||||
result.value = thisOverlay->getProperty(property);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
OverlayPropertyResult::OverlayPropertyResult() :
|
||||
value(QScriptValue())
|
||||
{
|
||||
}
|
||||
|
||||
QScriptValue OverlayPropertyResultToScriptValue(QScriptEngine* engine, const OverlayPropertyResult& result)
|
||||
{
|
||||
if (!result.value.isValid()) {
|
||||
return QScriptValue::UndefinedValue;
|
||||
}
|
||||
|
||||
QScriptValue object = engine->newObject();
|
||||
if (result.value.isObject()) {
|
||||
QScriptValueIterator it(result.value);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
object.setProperty(it.name(), QScriptValue(it.value().toString()));
|
||||
}
|
||||
|
||||
} else {
|
||||
object = result.value;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
void OverlayPropertyResultFromScriptValue(const QScriptValue& value, OverlayPropertyResult& result)
|
||||
{
|
||||
result.value = value;
|
||||
}
|
||||
|
||||
RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray) {
|
||||
float bestDistance = std::numeric_limits<float>::max();
|
||||
RayToOverlayIntersectionResult result;
|
||||
|
|
|
@ -16,6 +16,17 @@
|
|||
|
||||
#include "Overlay.h"
|
||||
|
||||
class OverlayPropertyResult {
|
||||
public:
|
||||
OverlayPropertyResult();
|
||||
QScriptValue value;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(OverlayPropertyResult);
|
||||
|
||||
QScriptValue OverlayPropertyResultToScriptValue(QScriptEngine* engine, const OverlayPropertyResult& value);
|
||||
void OverlayPropertyResultFromScriptValue(const QScriptValue& object, OverlayPropertyResult& value);
|
||||
|
||||
class RayToOverlayIntersectionResult {
|
||||
public:
|
||||
RayToOverlayIntersectionResult();
|
||||
|
@ -27,6 +38,7 @@ public:
|
|||
QString extraInfo;
|
||||
};
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(RayToOverlayIntersectionResult);
|
||||
|
||||
QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, const RayToOverlayIntersectionResult& value);
|
||||
|
@ -59,6 +71,9 @@ public slots:
|
|||
/// returns the top most 2D overlay at the screen point, or 0 if not overlay at that point
|
||||
unsigned int getOverlayAtPoint(const glm::vec2& point);
|
||||
|
||||
/// returns the value of specified property, or null if there is no such property
|
||||
OverlayPropertyResult getProperty(unsigned int id, const QString& property);
|
||||
|
||||
/// returns details about the closest 3D Overlay hit by the pick ray
|
||||
RayToOverlayIntersectionResult findRayIntersection(const PickRay& ray);
|
||||
|
||||
|
@ -77,6 +92,7 @@ private:
|
|||
QGLWidget* _parent;
|
||||
QReadWriteLock _lock;
|
||||
QReadWriteLock _deleteLock;
|
||||
QScriptEngine* _scriptEngine;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -77,6 +77,14 @@ void Planar3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "dimensions" || property == "scale" || property == "size") {
|
||||
return vec2toScriptValue(_scriptEngine, _dimensions);
|
||||
}
|
||||
|
||||
Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
void setDimensions(const glm::vec2& value) { _dimensions = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
|
||||
|
|
|
@ -180,9 +180,38 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
|
||||
}
|
||||
|
||||
QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "text") {
|
||||
return _text;
|
||||
}
|
||||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "lineHeight") {
|
||||
return _lineHeight;
|
||||
}
|
||||
if (property == "leftMargin") {
|
||||
return _leftMargin;
|
||||
}
|
||||
if (property == "topMargin") {
|
||||
return _topMargin;
|
||||
}
|
||||
if (property == "rightMargin") {
|
||||
return _rightMargin;
|
||||
}
|
||||
if (property == "bottomMargin") {
|
||||
return _bottomMargin;
|
||||
}
|
||||
if (property == "isFacingAvatar") {
|
||||
return _isFacingAvatar;
|
||||
}
|
||||
return Planar3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
float Text3DOverlay::textWidth(const QString& text) const {
|
||||
QFont font(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); // Same font properties as render()
|
||||
QFontMetrics fontMetrics(font);
|
||||
float scaleFactor = _lineHeight * LINE_SCALE_RATIO / (float)FIXED_FONT_POINT_SIZE;
|
||||
return scaleFactor * (float)fontMetrics.width(qPrintable(text));
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
float textWidth(const QString& text) const; // Meters
|
||||
|
||||
|
|
|
@ -124,6 +124,28 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue TextOverlay::getProperty(const QString& property) {
|
||||
if (property == "font") {
|
||||
QScriptValue font = _scriptEngine->newObject();
|
||||
font.setProperty("size", _fontSize);
|
||||
return font;
|
||||
}
|
||||
if (property == "text") {
|
||||
return _text;
|
||||
}
|
||||
if (property == "backgroundColor") {
|
||||
return xColorToScriptValue(_scriptEngine, _backgroundColor);
|
||||
}
|
||||
if (property == "leftMargin") {
|
||||
return _leftMargin;
|
||||
}
|
||||
if (property == "topMargin") {
|
||||
return _topMargin;
|
||||
}
|
||||
|
||||
return Overlay2D::getProperty(property);
|
||||
}
|
||||
|
||||
|
||||
float TextOverlay::textWidth(const QString& text) const {
|
||||
QFont font(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); // Same font properties as render()
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
void setFontSize(int fontSize) { _fontSize = fontSize; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
float textWidth(const QString& text) const; // Pixels
|
||||
|
||||
|
|
|
@ -85,6 +85,14 @@ void Volume3DOverlay::setProperties(const QScriptValue& properties) {
|
|||
}
|
||||
}
|
||||
|
||||
QScriptValue Volume3DOverlay::getProperty(const QString& property) {
|
||||
if (property == "dimensions" || property == "scale" || property == "size") {
|
||||
return vec3toScriptValue(_scriptEngine, _dimensions);
|
||||
}
|
||||
|
||||
return Base3DOverlay::getProperty(property);
|
||||
}
|
||||
|
||||
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) const {
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
void setDimensions(const glm::vec3& value) { _dimensions = value; }
|
||||
|
||||
virtual void setProperties(const QScriptValue& properties);
|
||||
virtual QScriptValue getProperty(const QString& property);
|
||||
|
||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QColor>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <QRect>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
|
@ -30,6 +31,7 @@ void registerMetaTypes(QScriptEngine* engine) {
|
|||
qScriptRegisterMetaType(engine, vec3toScriptValue, vec3FromScriptValue);
|
||||
qScriptRegisterMetaType(engine, vec2toScriptValue, vec2FromScriptValue);
|
||||
qScriptRegisterMetaType(engine, quatToScriptValue, quatFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, qRectToScriptValue, qRectFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, xColorToScriptValue, xColorFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, qColorToScriptValue, qColorFromScriptValue);
|
||||
qScriptRegisterMetaType(engine, qURLToScriptValue, qURLFromScriptValue);
|
||||
|
@ -96,6 +98,22 @@ void quatFromScriptValue(const QScriptValue &object, glm::quat& quat) {
|
|||
quat.w = object.property("w").toVariant().toFloat();
|
||||
}
|
||||
|
||||
QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("x", rect.x());
|
||||
obj.setProperty("y", rect.y());
|
||||
obj.setProperty("width", rect.width());
|
||||
obj.setProperty("height", rect.height());
|
||||
return obj;
|
||||
}
|
||||
|
||||
void qRectFromScriptValue(const QScriptValue &object, QRect& rect) {
|
||||
rect.setX(object.property("x").toVariant().toInt());
|
||||
rect.setY(object.property("y").toVariant().toInt());
|
||||
rect.setWidth(object.property("width").toVariant().toInt());
|
||||
rect.setHeight(object.property("height").toVariant().toInt());
|
||||
}
|
||||
|
||||
QScriptValue xColorToScriptValue(QScriptEngine *engine, const xColor& color) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("red", color.red);
|
||||
|
|
|
@ -42,6 +42,9 @@ void vec2FromScriptValue(const QScriptValue &object, glm::vec2 &vec2);
|
|||
QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat& quat);
|
||||
void quatFromScriptValue(const QScriptValue &object, glm::quat& quat);
|
||||
|
||||
QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect);
|
||||
void qRectFromScriptValue(const QScriptValue& object, QRect& rect);
|
||||
|
||||
QScriptValue xColorToScriptValue(QScriptEngine* engine, const xColor& color);
|
||||
void xColorFromScriptValue(const QScriptValue &object, xColor& color);
|
||||
|
||||
|
|
Loading…
Reference in a new issue