Merge pull request #7149 from jherico/overlays_qml

Make Overlay API usable from QML
This commit is contained in:
Brad Hefta-Gaub 2016-03-04 15:00:45 -08:00
commit 30bcb04a2f
43 changed files with 540 additions and 550 deletions

View file

@ -11,8 +11,6 @@
#include "Base3DOverlay.h" #include "Base3DOverlay.h"
#include <QScriptValue>
#include <RegisteredMetaTypes.h> #include <RegisteredMetaTypes.h>
#include <SharedUtil.h> #include <SharedUtil.h>
@ -41,103 +39,78 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) :
{ {
} }
void Base3DOverlay::setProperties(const QScriptValue& properties) { void Base3DOverlay::setProperties(const QVariantMap& properties) {
Overlay::setProperties(properties); Overlay::setProperties(properties);
QScriptValue drawInFront = properties.property("drawInFront"); auto drawInFront = properties["drawInFront"];
if (drawInFront.isValid()) { if (drawInFront.isValid()) {
bool value = drawInFront.toVariant().toBool(); bool value = drawInFront.toBool();
setDrawInFront(value); setDrawInFront(value);
} }
QScriptValue position = properties.property("position"); auto position = properties["position"];
// if "position" property was not there, check to see if they included aliases: point, p1 // if "position" property was not there, check to see if they included aliases: point, p1
if (!position.isValid()) { if (!position.isValid()) {
position = properties.property("p1"); position = properties["p1"];
if (!position.isValid()) { if (!position.isValid()) {
position = properties.property("point"); position = properties["point"];
} }
} }
if (position.isValid()) { if (position.isValid()) {
QScriptValue x = position.property("x"); setPosition(vec3FromVariant(position));
QScriptValue y = position.property("y");
QScriptValue z = position.property("z");
if (x.isValid() && y.isValid() && z.isValid()) {
glm::vec3 newPosition;
newPosition.x = x.toVariant().toFloat();
newPosition.y = y.toVariant().toFloat();
newPosition.z = z.toVariant().toFloat();
setPosition(newPosition);
}
} }
if (properties.property("lineWidth").isValid()) { if (properties["lineWidth"].isValid()) {
setLineWidth(properties.property("lineWidth").toVariant().toFloat()); setLineWidth(properties["lineWidth"].toFloat());
} }
QScriptValue rotation = properties.property("rotation"); auto rotation = properties["rotation"];
if (rotation.isValid()) { if (rotation.isValid()) {
glm::quat newRotation; setRotation(quatFromVariant(rotation));
// size, scale, dimensions is special, it might just be a single scalar, or it might be a vector, check that here
QScriptValue x = rotation.property("x");
QScriptValue y = rotation.property("y");
QScriptValue z = rotation.property("z");
QScriptValue w = rotation.property("w");
if (x.isValid() && y.isValid() && z.isValid() && w.isValid()) {
newRotation.x = x.toVariant().toFloat();
newRotation.y = y.toVariant().toFloat();
newRotation.z = z.toVariant().toFloat();
newRotation.w = w.toVariant().toFloat();
setRotation(newRotation);
}
} }
if (properties.property("isSolid").isValid()) { if (properties["isSolid"].isValid()) {
setIsSolid(properties.property("isSolid").toVariant().toBool()); setIsSolid(properties["isSolid"].toBool());
} }
if (properties.property("isFilled").isValid()) { if (properties["isFilled"].isValid()) {
setIsSolid(properties.property("isSolid").toVariant().toBool()); setIsSolid(properties["isSolid"].toBool());
} }
if (properties.property("isWire").isValid()) { if (properties["isWire"].isValid()) {
setIsSolid(!properties.property("isWire").toVariant().toBool()); setIsSolid(!properties["isWire"].toBool());
} }
if (properties.property("solid").isValid()) { if (properties["solid"].isValid()) {
setIsSolid(properties.property("solid").toVariant().toBool()); setIsSolid(properties["solid"].toBool());
} }
if (properties.property("filled").isValid()) { if (properties["filled"].isValid()) {
setIsSolid(properties.property("filled").toVariant().toBool()); setIsSolid(properties["filled"].toBool());
} }
if (properties.property("wire").isValid()) { if (properties["wire"].isValid()) {
setIsSolid(!properties.property("wire").toVariant().toBool()); setIsSolid(!properties["wire"].toBool());
} }
if (properties.property("isDashedLine").isValid()) { if (properties["isDashedLine"].isValid()) {
setIsDashedLine(properties.property("isDashedLine").toVariant().toBool()); setIsDashedLine(properties["isDashedLine"].toBool());
} }
if (properties.property("dashed").isValid()) { if (properties["dashed"].isValid()) {
setIsDashedLine(properties.property("dashed").toVariant().toBool()); setIsDashedLine(properties["dashed"].toBool());
} }
if (properties.property("ignoreRayIntersection").isValid()) { if (properties["ignoreRayIntersection"].isValid()) {
setIgnoreRayIntersection(properties.property("ignoreRayIntersection").toVariant().toBool()); setIgnoreRayIntersection(properties["ignoreRayIntersection"].toBool());
} }
} }
QScriptValue Base3DOverlay::getProperty(const QString& property) { QVariant Base3DOverlay::getProperty(const QString& property) {
if (property == "position" || property == "start" || property == "p1" || property == "point") { if (property == "position" || property == "start" || property == "p1" || property == "point") {
return vec3toScriptValue(_scriptEngine, getPosition()); return vec3toVariant(getPosition());
} }
if (property == "lineWidth") { if (property == "lineWidth") {
return _lineWidth; return _lineWidth;
} }
if (property == "rotation") { if (property == "rotation") {
return quatToScriptValue(_scriptEngine, getRotation()); return quatToVariant(getRotation());
} }
if (property == "isSolid" || property == "isFilled" || property == "solid" || property == "filed") { if (property == "isSolid" || property == "isFilled" || property == "solid" || property == "filed") {
return _isSolid; return _isSolid;

View file

@ -52,8 +52,8 @@ public:
virtual AABox getBounds() const = 0; virtual AABox getBounds() const = 0;
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);

View file

@ -18,19 +18,19 @@ Billboard3DOverlay::Billboard3DOverlay(const Billboard3DOverlay* billboard3DOver
{ {
} }
void Billboard3DOverlay::setProperties(const QScriptValue &properties) { void Billboard3DOverlay::setProperties(const QVariantMap& properties) {
Planar3DOverlay::setProperties(properties); Planar3DOverlay::setProperties(properties);
PanelAttachable::setProperties(properties); PanelAttachable::setProperties(properties);
Billboardable::setProperties(properties); Billboardable::setProperties(properties);
} }
QScriptValue Billboard3DOverlay::getProperty(const QString &property) { QVariant Billboard3DOverlay::getProperty(const QString &property) {
QScriptValue value; QVariant value;
value = Billboardable::getProperty(_scriptEngine, property); value = Billboardable::getProperty(property);
if (value.isValid()) { if (value.isValid()) {
return value; return value;
} }
value = PanelAttachable::getProperty(_scriptEngine, property); value = PanelAttachable::getProperty(property);
if (value.isValid()) { if (value.isValid()) {
return value; return value;
} }

View file

@ -23,8 +23,8 @@ public:
Billboard3DOverlay() {} Billboard3DOverlay() {}
Billboard3DOverlay(const Billboard3DOverlay* billboard3DOverlay); Billboard3DOverlay(const Billboard3DOverlay* billboard3DOverlay);
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
protected: protected:
virtual void applyTransformTo(Transform& transform, bool force = false); virtual void applyTransformTo(Transform& transform, bool force = false);

View file

@ -14,18 +14,18 @@
#include <Application.h> #include <Application.h>
#include <Transform.h> #include <Transform.h>
void Billboardable::setProperties(const QScriptValue &properties) { void Billboardable::setProperties(const QVariantMap& properties) {
QScriptValue isFacingAvatar = properties.property("isFacingAvatar"); auto isFacingAvatar = properties["isFacingAvatar"];
if (isFacingAvatar.isValid()) { if (isFacingAvatar.isValid()) {
setIsFacingAvatar(isFacingAvatar.toVariant().toBool()); setIsFacingAvatar(isFacingAvatar.toBool());
} }
} }
QScriptValue Billboardable::getProperty(QScriptEngine* scriptEngine, const QString &property) { QVariant Billboardable::getProperty(const QString &property) {
if (property == "isFacingAvatar") { if (property == "isFacingAvatar") {
return isFacingAvatar(); return isFacingAvatar();
} }
return QScriptValue(); return QVariant();
} }
void Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offsetRotation) { void Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offsetRotation) {

View file

@ -12,11 +12,9 @@
#ifndef hifi_Billboardable_h #ifndef hifi_Billboardable_h
#define hifi_Billboardable_h #define hifi_Billboardable_h
#include <QScriptValue>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include <QVariant>
class QScriptEngine;
class QString; class QString;
class Transform; class Transform;
@ -26,8 +24,8 @@ public:
void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; } void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; }
protected: protected:
void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties);
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property); QVariant getProperty(const QString& property);
void pointTransformAtCamera(Transform& transform, glm::quat offsetRotation = {1, 0, 0, 0}); void pointTransformAtCamera(Transform& transform, glm::quat offsetRotation = {1, 0, 0, 0});

View file

@ -286,83 +286,76 @@ const render::ShapeKey Circle3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Circle3DOverlay::setProperties(const QScriptValue &properties) { void Circle3DOverlay::setProperties(const QVariantMap& properties) {
Planar3DOverlay::setProperties(properties); Planar3DOverlay::setProperties(properties);
QScriptValue startAt = properties.property("startAt"); QVariant startAt = properties["startAt"];
if (startAt.isValid()) { if (startAt.isValid()) {
setStartAt(startAt.toVariant().toFloat()); setStartAt(startAt.toFloat());
} }
QScriptValue endAt = properties.property("endAt"); QVariant endAt = properties["endAt"];
if (endAt.isValid()) { if (endAt.isValid()) {
setEndAt(endAt.toVariant().toFloat()); setEndAt(endAt.toFloat());
} }
QScriptValue outerRadius = properties.property("radius"); QVariant outerRadius = properties["radius"];
if (!outerRadius.isValid()) { if (!outerRadius.isValid()) {
outerRadius = properties.property("outerRadius"); outerRadius = properties["outerRadius"];
} }
if (outerRadius.isValid()) { if (outerRadius.isValid()) {
setOuterRadius(outerRadius.toVariant().toFloat()); setOuterRadius(outerRadius.toFloat());
} }
QScriptValue innerRadius = properties.property("innerRadius"); QVariant innerRadius = properties["innerRadius"];
if (innerRadius.isValid()) { if (innerRadius.isValid()) {
setInnerRadius(innerRadius.toVariant().toFloat()); setInnerRadius(innerRadius.toFloat());
} }
QScriptValue hasTickMarks = properties.property("hasTickMarks"); QVariant hasTickMarks = properties["hasTickMarks"];
if (hasTickMarks.isValid()) { if (hasTickMarks.isValid()) {
setHasTickMarks(hasTickMarks.toVariant().toBool()); setHasTickMarks(hasTickMarks.toBool());
} }
QScriptValue majorTickMarksAngle = properties.property("majorTickMarksAngle"); QVariant majorTickMarksAngle = properties["majorTickMarksAngle"];
if (majorTickMarksAngle.isValid()) { if (majorTickMarksAngle.isValid()) {
setMajorTickMarksAngle(majorTickMarksAngle.toVariant().toFloat()); setMajorTickMarksAngle(majorTickMarksAngle.toFloat());
} }
QScriptValue minorTickMarksAngle = properties.property("minorTickMarksAngle"); QVariant minorTickMarksAngle = properties["minorTickMarksAngle"];
if (minorTickMarksAngle.isValid()) { if (minorTickMarksAngle.isValid()) {
setMinorTickMarksAngle(minorTickMarksAngle.toVariant().toFloat()); setMinorTickMarksAngle(minorTickMarksAngle.toFloat());
} }
QScriptValue majorTickMarksLength = properties.property("majorTickMarksLength"); QVariant majorTickMarksLength = properties["majorTickMarksLength"];
if (majorTickMarksLength.isValid()) { if (majorTickMarksLength.isValid()) {
setMajorTickMarksLength(majorTickMarksLength.toVariant().toFloat()); setMajorTickMarksLength(majorTickMarksLength.toFloat());
} }
QScriptValue minorTickMarksLength = properties.property("minorTickMarksLength"); QVariant minorTickMarksLength = properties["minorTickMarksLength"];
if (minorTickMarksLength.isValid()) { if (minorTickMarksLength.isValid()) {
setMinorTickMarksLength(minorTickMarksLength.toVariant().toFloat()); setMinorTickMarksLength(minorTickMarksLength.toFloat());
} }
QScriptValue majorTickMarksColor = properties.property("majorTickMarksColor"); bool valid;
auto majorTickMarksColor = properties["majorTickMarksColor"];
if (majorTickMarksColor.isValid()) { if (majorTickMarksColor.isValid()) {
QScriptValue red = majorTickMarksColor.property("red"); auto color = xColorFromVariant(majorTickMarksColor, valid);
QScriptValue green = majorTickMarksColor.property("green"); if (valid) {
QScriptValue blue = majorTickMarksColor.property("blue"); _majorTickMarksColor = color;
if (red.isValid() && green.isValid() && blue.isValid()) {
_majorTickMarksColor.red = red.toVariant().toInt();
_majorTickMarksColor.green = green.toVariant().toInt();
_majorTickMarksColor.blue = blue.toVariant().toInt();
} }
} }
QScriptValue minorTickMarksColor = properties.property("minorTickMarksColor"); auto minorTickMarksColor = properties["minorTickMarksColor"];
if (minorTickMarksColor.isValid()) { if (minorTickMarksColor.isValid()) {
QScriptValue red = minorTickMarksColor.property("red"); auto color = xColorFromVariant(majorTickMarksColor, valid);
QScriptValue green = minorTickMarksColor.property("green"); if (valid) {
QScriptValue blue = minorTickMarksColor.property("blue"); _minorTickMarksColor = color;
if (red.isValid() && green.isValid() && blue.isValid()) {
_minorTickMarksColor.red = red.toVariant().toInt();
_minorTickMarksColor.green = green.toVariant().toInt();
_minorTickMarksColor.blue = blue.toVariant().toInt();
} }
} }
} }
QScriptValue Circle3DOverlay::getProperty(const QString& property) { QVariant Circle3DOverlay::getProperty(const QString& property) {
if (property == "startAt") { if (property == "startAt") {
return _startAt; return _startAt;
} }
@ -394,10 +387,10 @@ QScriptValue Circle3DOverlay::getProperty(const QString& property) {
return _minorTickMarksLength; return _minorTickMarksLength;
} }
if (property == "majorTickMarksColor") { if (property == "majorTickMarksColor") {
return xColorToScriptValue(_scriptEngine, _majorTickMarksColor); return xColorToVariant(_majorTickMarksColor);
} }
if (property == "minorTickMarksColor") { if (property == "minorTickMarksColor") {
return xColorToScriptValue(_scriptEngine, _minorTickMarksColor); return xColorToVariant(_minorTickMarksColor);
} }
return Planar3DOverlay::getProperty(property); return Planar3DOverlay::getProperty(property);

View file

@ -26,8 +26,8 @@ public:
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);
virtual const render::ShapeKey getShapeKey() override; virtual const render::ShapeKey getShapeKey() override;
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
float getStartAt() const { return _startAt; } float getStartAt() const { return _startAt; }
float getEndAt() const { return _endAt; } float getEndAt() const { return _endAt; }

View file

@ -11,8 +11,6 @@
// include this before QGLWidget, which includes an earlier version of OpenGL // include this before QGLWidget, which includes an earlier version of OpenGL
#include "Cube3DOverlay.h" #include "Cube3DOverlay.h"
#include <QScriptValue>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <StreamUtils.h> #include <StreamUtils.h>
#include <GeometryCache.h> #include <GeometryCache.h>
@ -110,18 +108,18 @@ Cube3DOverlay* Cube3DOverlay::createClone() const {
return new Cube3DOverlay(this); return new Cube3DOverlay(this);
} }
void Cube3DOverlay::setProperties(const QScriptValue& properties) { void Cube3DOverlay::setProperties(const QVariantMap& properties) {
Volume3DOverlay::setProperties(properties); Volume3DOverlay::setProperties(properties);
QScriptValue borderSize = properties.property("borderSize"); auto borderSize = properties["borderSize"];
if (borderSize.isValid()) { if (borderSize.isValid()) {
float value = borderSize.toVariant().toFloat(); float value = borderSize.toFloat();
setBorderSize(value); setBorderSize(value);
} }
} }
QScriptValue Cube3DOverlay::getProperty(const QString& property) { QVariant Cube3DOverlay::getProperty(const QString& property) {
if (property == "borderSize") { if (property == "borderSize") {
return _borderSize; return _borderSize;
} }

View file

@ -32,8 +32,8 @@ public:
void setBorderSize(float value) { _borderSize = value; } void setBorderSize(float value) { _borderSize = value; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
private: private:
float _borderSize; float _borderSize;

View file

@ -11,10 +11,7 @@
#include "Grid3DOverlay.h" #include "Grid3DOverlay.h"
#include <QScriptValue>
#include <OctreeConstants.h> #include <OctreeConstants.h>
#include <DependencyManager.h> #include <DependencyManager.h>
#include <GeometryCache.h> #include <GeometryCache.h>
#include <PathUtils.h> #include <PathUtils.h>
@ -92,24 +89,24 @@ const render::ShapeKey Grid3DOverlay::getShapeKey() {
return render::ShapeKey::Builder().withOwnPipeline(); return render::ShapeKey::Builder().withOwnPipeline();
} }
void Grid3DOverlay::setProperties(const QScriptValue& properties) { void Grid3DOverlay::setProperties(const QVariantMap& properties) {
Planar3DOverlay::setProperties(properties); Planar3DOverlay::setProperties(properties);
if (properties.property("followCamera").isValid()) { if (properties["followCamera"].isValid()) {
_followCamera = properties.property("followCamera").toVariant().toBool(); _followCamera = properties["followCamera"].toBool();
} }
if (properties.property("majorGridEvery").isValid()) { if (properties["majorGridEvery"].isValid()) {
_majorGridEvery = properties.property("majorGridEvery").toVariant().toInt(); _majorGridEvery = properties["majorGridEvery"].toInt();
} }
if (properties.property("minorGridEvery").isValid()) { if (properties["minorGridEvery"].isValid()) {
_minorGridEvery = properties.property("minorGridEvery").toVariant().toFloat(); _minorGridEvery = properties["minorGridEvery"].toFloat();
} }
updateGrid(); updateGrid();
} }
QScriptValue Grid3DOverlay::getProperty(const QString& property) { QVariant Grid3DOverlay::getProperty(const QString& property) {
if (property == "followCamera") { if (property == "followCamera") {
return _followCamera; return _followCamera;
} }

View file

@ -28,8 +28,8 @@ public:
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);
virtual const render::ShapeKey getShapeKey() override; virtual const render::ShapeKey getShapeKey() override;
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual Grid3DOverlay* createClone() const; virtual Grid3DOverlay* createClone() const;

View file

@ -12,8 +12,6 @@
#include "Image3DOverlay.h" #include "Image3DOverlay.h"
#include <QScriptValue>
#include <DependencyManager.h> #include <DependencyManager.h>
#include <GeometryCache.h> #include <GeometryCache.h>
#include <gpu/Batch.h> #include <gpu/Batch.h>
@ -114,41 +112,42 @@ const render::ShapeKey Image3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Image3DOverlay::setProperties(const QScriptValue &properties) { void Image3DOverlay::setProperties(const QVariantMap& properties) {
Billboard3DOverlay::setProperties(properties); Billboard3DOverlay::setProperties(properties);
QScriptValue urlValue = properties.property("url"); auto urlValue = properties["url"];
if (urlValue.isValid()) { if (urlValue.isValid()) {
QString newURL = urlValue.toVariant().toString(); QString newURL = urlValue.toString();
if (newURL != _url) { if (newURL != _url) {
setURL(newURL); setURL(newURL);
} }
} }
QScriptValue subImageBounds = properties.property("subImage"); auto subImageBoundsVar = properties["subImage"];
if (subImageBounds.isValid()) { if (subImageBoundsVar.isValid()) {
if (subImageBounds.isNull()) { if (subImageBoundsVar.isNull()) {
_fromImage = QRect(); _fromImage = QRect();
} else { } else {
QRect oldSubImageRect = _fromImage; QRect oldSubImageRect = _fromImage;
QRect subImageRect = _fromImage; QRect subImageRect = _fromImage;
if (subImageBounds.property("x").isValid()) { auto subImageBounds = subImageBoundsVar.toMap();
subImageRect.setX(subImageBounds.property("x").toVariant().toInt()); if (subImageBounds["x"].isValid()) {
subImageRect.setX(subImageBounds["x"].toInt());
} else { } else {
subImageRect.setX(oldSubImageRect.x()); subImageRect.setX(oldSubImageRect.x());
} }
if (subImageBounds.property("y").isValid()) { if (subImageBounds["y"].isValid()) {
subImageRect.setY(subImageBounds.property("y").toVariant().toInt()); subImageRect.setY(subImageBounds["y"].toInt());
} else { } else {
subImageRect.setY(oldSubImageRect.y()); subImageRect.setY(oldSubImageRect.y());
} }
if (subImageBounds.property("width").isValid()) { if (subImageBounds["width"].isValid()) {
subImageRect.setWidth(subImageBounds.property("width").toVariant().toInt()); subImageRect.setWidth(subImageBounds["width"].toInt());
} else { } else {
subImageRect.setWidth(oldSubImageRect.width()); subImageRect.setWidth(oldSubImageRect.width());
} }
if (subImageBounds.property("height").isValid()) { if (subImageBounds["height"].isValid()) {
subImageRect.setHeight(subImageBounds.property("height").toVariant().toInt()); subImageRect.setHeight(subImageBounds["height"].toInt());
} else { } else {
subImageRect.setHeight(oldSubImageRect.height()); subImageRect.setHeight(oldSubImageRect.height());
} }
@ -156,21 +155,21 @@ void Image3DOverlay::setProperties(const QScriptValue &properties) {
} }
} }
QScriptValue emissiveValue = properties.property("emissive"); auto emissiveValue = properties["emissive"];
if (emissiveValue.isValid()) { if (emissiveValue.isValid()) {
_emissive = emissiveValue.toBool(); _emissive = emissiveValue.toBool();
} }
} }
QScriptValue Image3DOverlay::getProperty(const QString& property) { QVariant Image3DOverlay::getProperty(const QString& property) {
if (property == "url") { if (property == "url") {
return _url; return _url;
} }
if (property == "subImage") { if (property == "subImage") {
return qRectToScriptValue(_scriptEngine, _fromImage); return _fromImage;
} }
if (property == "offsetPosition") { if (property == "offsetPosition") {
return vec3toScriptValue(_scriptEngine, getOffsetPosition()); return vec3toVariant(getOffsetPosition());
} }
if (property == "emissive") { if (property == "emissive") {
return _emissive; return _emissive;

View file

@ -37,8 +37,8 @@ public:
void setURL(const QString& url); void setURL(const QString& url);
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; } void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);

View file

@ -71,49 +71,34 @@ const render::ShapeKey Line3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Line3DOverlay::setProperties(const QScriptValue& properties) { void Line3DOverlay::setProperties(const QVariantMap& properties) {
Base3DOverlay::setProperties(properties); Base3DOverlay::setProperties(properties);
QScriptValue start = properties.property("start"); auto start = properties["start"];
// if "start" property was not there, check to see if they included aliases: startPoint // if "start" property was not there, check to see if they included aliases: startPoint
if (!start.isValid()) { if (!start.isValid()) {
start = properties.property("startPoint"); start = properties["startPoint"];
} }
if (start.isValid()) { if (start.isValid()) {
QScriptValue x = start.property("x"); setStart(vec3FromVariant(start));
QScriptValue y = start.property("y");
QScriptValue z = start.property("z");
if (x.isValid() && y.isValid() && z.isValid()) {
glm::vec3 newStart;
newStart.x = x.toVariant().toFloat();
newStart.y = y.toVariant().toFloat();
newStart.z = z.toVariant().toFloat();
setStart(newStart);
}
} }
QScriptValue end = properties.property("end"); auto end = properties["end"];
// if "end" property was not there, check to see if they included aliases: endPoint // if "end" property was not there, check to see if they included aliases: endPoint
if (!end.isValid()) { if (!end.isValid()) {
end = properties.property("endPoint"); end = properties["endPoint"];
} }
if (end.isValid()) { if (end.isValid()) {
QScriptValue x = end.property("x"); setEnd(vec3FromVariant(end));
QScriptValue y = end.property("y");
QScriptValue z = end.property("z");
if (x.isValid() && y.isValid() && z.isValid()) {
glm::vec3 newEnd;
newEnd.x = x.toVariant().toFloat();
newEnd.y = y.toVariant().toFloat();
newEnd.z = z.toVariant().toFloat();
setEnd(newEnd);
}
} }
} }
QScriptValue Line3DOverlay::getProperty(const QString& property) { QVariant Line3DOverlay::getProperty(const QString& property) {
if (property == "start" || property == "startPoint" || property == "p1") {
return vec3toVariant(_start);
}
if (property == "end" || property == "endPoint" || property == "p2") { if (property == "end" || property == "endPoint" || property == "p2") {
return vec3toScriptValue(_scriptEngine, _end); return vec3toVariant(_end);
} }
return Base3DOverlay::getProperty(property); return Base3DOverlay::getProperty(property);

View file

@ -35,8 +35,8 @@ public:
void setStart(const glm::vec3& start) { _start = start; } void setStart(const glm::vec3& start) { _start = start; }
void setEnd(const glm::vec3& end) { _end = end; } void setEnd(const glm::vec3& end) { _end = end; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual Line3DOverlay* createClone() const; virtual Line3DOverlay* createClone() const;

View file

@ -84,7 +84,7 @@ void ModelOverlay::render(RenderArgs* args) {
} }
} }
void ModelOverlay::setProperties(const QScriptValue &properties) { void ModelOverlay::setProperties(const QVariantMap& properties) {
auto position = getPosition(); auto position = getPosition();
auto rotation = getRotation(); auto rotation = getRotation();
auto scale = getDimensions(); auto scale = getDimensions();
@ -105,16 +105,16 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
} }
} }
QScriptValue urlValue = properties.property("url"); auto urlValue = properties["url"];
if (urlValue.isValid() && urlValue.isString()) { if (urlValue.isValid() && urlValue.canConvert<QString>()) {
_url = urlValue.toString(); _url = urlValue.toString();
_updateModel = true; _updateModel = true;
_isLoaded = false; _isLoaded = false;
} }
QScriptValue texturesValue = properties.property("textures"); auto texturesValue = properties["textures"];
if (texturesValue.isValid() && texturesValue.toVariant().canConvert(QVariant::Map)) { if (texturesValue.isValid() && texturesValue.canConvert(QVariant::Map)) {
QVariantMap textureMap = texturesValue.toVariant().toMap(); QVariantMap textureMap = texturesValue.toMap();
foreach(const QString& key, textureMap.keys()) { foreach(const QString& key, textureMap.keys()) {
QUrl newTextureURL = textureMap[key].toUrl(); QUrl newTextureURL = textureMap[key].toUrl();
@ -129,22 +129,22 @@ void ModelOverlay::setProperties(const QScriptValue &properties) {
} }
} }
QScriptValue ModelOverlay::getProperty(const QString& property) { QVariant ModelOverlay::getProperty(const QString& property) {
if (property == "url") { if (property == "url") {
return _url.toString(); return _url.toString();
} }
if (property == "dimensions" || property == "scale" || property == "size") { if (property == "dimensions" || property == "scale" || property == "size") {
return vec3toScriptValue(_scriptEngine, _model.getScaleToFitDimensions()); return vec3toVariant(_model.getScaleToFitDimensions());
} }
if (property == "textures") { if (property == "textures") {
if (_modelTextures.size() > 0) { if (_modelTextures.size() > 0) {
QScriptValue textures = _scriptEngine->newObject(); QVariantMap textures;
foreach(const QString& key, _modelTextures.keys()) { foreach(const QString& key, _modelTextures.keys()) {
textures.setProperty(key, _modelTextures[key].toString()); textures[key] = _modelTextures[key].toString();
} }
return textures; return textures;
} else { } else {
return QScriptValue(); return QVariant();
} }
} }

View file

@ -27,9 +27,9 @@ public:
virtual void update(float deltatime); virtual void update(float deltatime);
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction, virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, QString& extraInfo); float& distance, BoxFace& face, glm::vec3& surfaceNormal, QString& extraInfo);

View file

@ -52,70 +52,68 @@ Overlay::Overlay(const Overlay* overlay) :
_colorPulse(overlay->_colorPulse), _colorPulse(overlay->_colorPulse),
_color(overlay->_color), _color(overlay->_color),
_visible(overlay->_visible), _visible(overlay->_visible),
_anchor(overlay->_anchor), _anchor(overlay->_anchor)
_scriptEngine(NULL)
{ {
} }
void Overlay::init(QScriptEngine* scriptEngine) {
_scriptEngine = scriptEngine;
}
Overlay::~Overlay() { Overlay::~Overlay() {
} }
void Overlay::setProperties(const QScriptValue& properties) { void Overlay::setProperties(const QVariantMap& properties) {
QScriptValue color = properties.property("color"); bool valid;
xColorFromScriptValue(properties.property("color"), _color); auto color = xColorFromVariant(properties["color"], valid);
if (valid) {
_color = color;
}
if (properties.property("alpha").isValid()) { if (properties["alpha"].isValid()) {
setAlpha(properties.property("alpha").toVariant().toFloat()); setAlpha(properties["alpha"].toFloat());
} }
if (properties.property("glowLevel").isValid()) { if (properties["glowLevel"].isValid()) {
setGlowLevel(properties.property("glowLevel").toVariant().toFloat()); setGlowLevel(properties["glowLevel"].toFloat());
} }
if (properties.property("pulseMax").isValid()) { if (properties["pulseMax"].isValid()) {
setPulseMax(properties.property("pulseMax").toVariant().toFloat()); setPulseMax(properties["pulseMax"].toFloat());
} }
if (properties.property("pulseMin").isValid()) { if (properties["pulseMin"].isValid()) {
setPulseMin(properties.property("pulseMin").toVariant().toFloat()); setPulseMin(properties["pulseMin"].toFloat());
} }
if (properties.property("pulsePeriod").isValid()) { if (properties["pulsePeriod"].isValid()) {
setPulsePeriod(properties.property("pulsePeriod").toVariant().toFloat()); setPulsePeriod(properties["pulsePeriod"].toFloat());
} }
if (properties.property("glowLevelPulse").isValid()) { if (properties["glowLevelPulse"].isValid()) {
setGlowLevelPulse(properties.property("glowLevelPulse").toVariant().toFloat()); setGlowLevelPulse(properties["glowLevelPulse"].toFloat());
} }
if (properties.property("alphaPulse").isValid()) { if (properties["alphaPulse"].isValid()) {
setAlphaPulse(properties.property("alphaPulse").toVariant().toFloat()); setAlphaPulse(properties["alphaPulse"].toFloat());
} }
if (properties.property("colorPulse").isValid()) { if (properties["colorPulse"].isValid()) {
setColorPulse(properties.property("colorPulse").toVariant().toFloat()); setColorPulse(properties["colorPulse"].toFloat());
} }
if (properties.property("visible").isValid()) { if (properties["visible"].isValid()) {
bool visible = properties.property("visible").toVariant().toBool(); bool visible = properties["visible"].toBool();
setVisible(visible); setVisible(visible);
} }
if (properties.property("anchor").isValid()) { if (properties["anchor"].isValid()) {
QString property = properties.property("anchor").toVariant().toString(); QString property = properties["anchor"].toString();
if (property == "MyAvatar") { if (property == "MyAvatar") {
setAnchor(MY_AVATAR); setAnchor(MY_AVATAR);
} }
} }
} }
QScriptValue Overlay::getProperty(const QString& property) { QVariant Overlay::getProperty(const QString& property) {
if (property == "color") { if (property == "color") {
return xColorToScriptValue(_scriptEngine, _color); return xColorToVariant(_color);
} }
if (property == "alpha") { if (property == "alpha") {
return _alpha; return _alpha;
@ -148,7 +146,7 @@ QScriptValue Overlay::getProperty(const QString& property) {
return _anchor == MY_AVATAR ? "MyAvatar" : ""; return _anchor == MY_AVATAR ? "MyAvatar" : "";
} }
return QScriptValue(); return QVariant();
} }
xColor Overlay::getColor() { xColor Overlay::getColor() {

View file

@ -15,9 +15,6 @@
#include <SharedUtil.h> // for xColor #include <SharedUtil.h> // for xColor
#include <render/Scene.h> #include <render/Scene.h>
class QScriptEngine;
class QScriptValue;
class Overlay : public QObject { class Overlay : public QObject {
Q_OBJECT Q_OBJECT
@ -34,7 +31,6 @@ public:
Overlay(); Overlay();
Overlay(const Overlay* overlay); Overlay(const Overlay* overlay);
~Overlay(); ~Overlay();
void init(QScriptEngine* scriptEngine);
virtual void update(float deltatime) {} virtual void update(float deltatime) {}
virtual void render(RenderArgs* args) = 0; virtual void render(RenderArgs* args) = 0;
@ -82,9 +78,9 @@ public:
void setColorPulse(float value) { _colorPulse = value; } void setColorPulse(float value) { _colorPulse = value; }
void setAlphaPulse(float value) { _alphaPulse = value; } void setAlphaPulse(float value) { _alphaPulse = value; }
virtual void setProperties(const QScriptValue& properties); virtual void setProperties(const QVariantMap& properties);
virtual Overlay* createClone() const = 0; virtual Overlay* createClone() const = 0;
virtual QScriptValue getProperty(const QString& property); virtual QVariant getProperty(const QString& property);
render::ItemID getRenderItemID() const { return _renderItemID; } render::ItemID getRenderItemID() const { return _renderItemID; }
void setRenderItemID(render::ItemID renderItemID) { _renderItemID = renderItemID; } void setRenderItemID(render::ItemID renderItemID) { _renderItemID = renderItemID; }
@ -112,8 +108,6 @@ protected:
xColor _color; xColor _color;
bool _visible; // should the overlay be drawn at all bool _visible; // should the overlay be drawn at all
Anchor _anchor; Anchor _anchor;
QScriptEngine* _scriptEngine;
}; };
namespace render { namespace render {

View file

@ -23,49 +23,44 @@ AABox Overlay2D::getBounds() const {
glm::vec3(_bounds.width(), _bounds.height(), 0.01f)); glm::vec3(_bounds.width(), _bounds.height(), 0.01f));
} }
void Overlay2D::setProperties(const QScriptValue& properties) { void Overlay2D::setProperties(const QVariantMap& properties) {
Overlay::setProperties(properties); Overlay::setProperties(properties);
QScriptValue bounds = properties.property("bounds"); auto bounds = properties["bounds"];
if (bounds.isValid()) { if (bounds.isValid()) {
QRect boundsRect; bool valid;
boundsRect.setX(bounds.property("x").toVariant().toInt()); auto rect = qRectFromVariant(bounds, valid);
boundsRect.setY(bounds.property("y").toVariant().toInt()); setBounds(rect);
boundsRect.setWidth(bounds.property("width").toVariant().toInt());
boundsRect.setHeight(bounds.property("height").toVariant().toInt());
setBounds(boundsRect);
} else { } else {
QRect oldBounds = _bounds; QRect oldBounds = _bounds;
QRect newBounds = oldBounds; QRect newBounds = oldBounds;
if (properties["x"].isValid()) {
if (properties.property("x").isValid()) { newBounds.setX(properties["x"].toInt());
newBounds.setX(properties.property("x").toVariant().toInt());
} else { } else {
newBounds.setX(oldBounds.x()); newBounds.setX(oldBounds.x());
} }
if (properties.property("y").isValid()) { if (properties["y"].isValid()) {
newBounds.setY(properties.property("y").toVariant().toInt()); newBounds.setY(properties["y"].toInt());
} else { } else {
newBounds.setY(oldBounds.y()); newBounds.setY(oldBounds.y());
} }
if (properties.property("width").isValid()) { if (properties["width"].isValid()) {
newBounds.setWidth(properties.property("width").toVariant().toInt()); newBounds.setWidth(properties["width"].toInt());
} else { } else {
newBounds.setWidth(oldBounds.width()); newBounds.setWidth(oldBounds.width());
} }
if (properties.property("height").isValid()) { if (properties["height"].isValid()) {
newBounds.setHeight(properties.property("height").toVariant().toInt()); newBounds.setHeight(properties["height"].toInt());
} else { } else {
newBounds.setHeight(oldBounds.height()); newBounds.setHeight(oldBounds.height());
} }
setBounds(newBounds); setBounds(newBounds);
//qDebug() << "set bounds to " << getBounds();
} }
} }
QScriptValue Overlay2D::getProperty(const QString& property) { QVariant Overlay2D::getProperty(const QString& property) {
if (property == "bounds") { if (property == "bounds") {
return qRectToScriptValue(_scriptEngine, _bounds); return qRectToVariant(_bounds);
} }
if (property == "x") { if (property == "x") {
return _bounds.x(); return _bounds.x();

View file

@ -40,8 +40,8 @@ public:
void setHeight(int height) { _bounds.setHeight(height); } void setHeight(int height) { _bounds.setHeight(height); }
void setBounds(const QRect& bounds) { _bounds = bounds; } void setBounds(const QRect& bounds) { _bounds = bounds; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
protected: protected:
QRect _bounds; // where on the screen to draw QRect _bounds; // where on the screen to draw

View file

@ -26,26 +26,27 @@ PropertyBinding::PropertyBinding(QString avatar, QUuid entity) :
{ {
} }
QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value) { QVariant propertyBindingToVariant(const PropertyBinding& value) {
QScriptValue obj = engine->newObject(); QVariantMap obj;
if (value.avatar == "MyAvatar") { if (value.avatar == "MyAvatar") {
obj.setProperty("avatar", "MyAvatar"); obj["avatar"] = "MyAvatar";
} else if (!value.entity.isNull()) { } else if (!value.entity.isNull()) {
obj.setProperty("entity", engine->newVariant(value.entity)); obj["entity"] = value.entity;
} }
return obj; return obj;
} }
void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value) { void propertyBindingFromVariant(const QVariant& objectVar, PropertyBinding& value) {
QScriptValue avatar = object.property("avatar"); auto object = objectVar.toMap();
QScriptValue entity = object.property("entity"); auto avatar = object["avatar"];
auto entity = object["entity"];
if (avatar.isValid() && !avatar.isNull()) { if (avatar.isValid() && !avatar.isNull()) {
value.avatar = avatar.toVariant().toString(); value.avatar = avatar.toString();
} else if (entity.isValid() && !entity.isNull()) { } else if (entity.isValid() && !entity.isNull()) {
value.entity = entity.toVariant().toUuid(); value.entity = entity.toUuid();
} }
} }
@ -62,103 +63,82 @@ void OverlayPanel::removeChild(unsigned int childId) {
} }
} }
QScriptValue OverlayPanel::getProperty(const QString &property) { QVariant OverlayPanel::getProperty(const QString &property) {
if (property == "anchorPosition") { if (property == "anchorPosition") {
return vec3toScriptValue(_scriptEngine, getAnchorPosition()); return vec3toVariant(getAnchorPosition());
} }
if (property == "anchorPositionBinding") { if (property == "anchorPositionBinding") {
return propertyBindingToScriptValue(_scriptEngine, return propertyBindingToVariant(PropertyBinding(_anchorPositionBindMyAvatar ?
PropertyBinding(_anchorPositionBindMyAvatar ?
"MyAvatar" : "", "MyAvatar" : "",
_anchorPositionBindEntity)); _anchorPositionBindEntity));
} }
if (property == "anchorRotation") { if (property == "anchorRotation") {
return quatToScriptValue(_scriptEngine, getAnchorRotation()); return quatToVariant(getAnchorRotation());
} }
if (property == "anchorRotationBinding") { if (property == "anchorRotationBinding") {
return propertyBindingToScriptValue(_scriptEngine, return propertyBindingToVariant(PropertyBinding(_anchorRotationBindMyAvatar ?
PropertyBinding(_anchorRotationBindMyAvatar ?
"MyAvatar" : "", "MyAvatar" : "",
_anchorRotationBindEntity)); _anchorRotationBindEntity));
} }
if (property == "anchorScale") { if (property == "anchorScale") {
return vec3toScriptValue(_scriptEngine, getAnchorScale()); return vec3toVariant(getAnchorScale());
} }
if (property == "visible") { if (property == "visible") {
return getVisible(); return getVisible();
} }
if (property == "children") { if (property == "children") {
QScriptValue array = _scriptEngine->newArray(_children.length()); QVariantList array;
for (int i = 0; i < _children.length(); i++) { for (int i = 0; i < _children.length(); i++) {
array.setProperty(i, _children[i]); array.append(_children[i]);
} }
return array; return array;
} }
QScriptValue value = Billboardable::getProperty(_scriptEngine, property); auto value = Billboardable::getProperty(property);
if (value.isValid()) { if (value.isValid()) {
return value; return value;
} }
return PanelAttachable::getProperty(_scriptEngine, property); return PanelAttachable::getProperty(property);
} }
void OverlayPanel::setProperties(const QScriptValue &properties) { void OverlayPanel::setProperties(const QVariantMap& properties) {
PanelAttachable::setProperties(properties); PanelAttachable::setProperties(properties);
Billboardable::setProperties(properties); Billboardable::setProperties(properties);
QScriptValue anchorPosition = properties.property("anchorPosition"); auto anchorPosition = properties["anchorPosition"];
if (anchorPosition.isValid() && if (anchorPosition.isValid()) {
anchorPosition.property("x").isValid() && setAnchorPosition(vec3FromVariant(anchorPosition));
anchorPosition.property("y").isValid() &&
anchorPosition.property("z").isValid()) {
glm::vec3 newPosition;
vec3FromScriptValue(anchorPosition, newPosition);
setAnchorPosition(newPosition);
} }
QScriptValue anchorPositionBinding = properties.property("anchorPositionBinding"); auto anchorPositionBinding = properties["anchorPositionBinding"];
if (anchorPositionBinding.isValid()) { if (anchorPositionBinding.isValid()) {
PropertyBinding binding = {}; PropertyBinding binding = {};
propertyBindingFromScriptValue(anchorPositionBinding, binding); propertyBindingFromVariant(anchorPositionBinding, binding);
_anchorPositionBindMyAvatar = binding.avatar == "MyAvatar"; _anchorPositionBindMyAvatar = binding.avatar == "MyAvatar";
_anchorPositionBindEntity = binding.entity; _anchorPositionBindEntity = binding.entity;
} }
QScriptValue anchorRotation = properties.property("anchorRotation"); auto anchorRotation = properties["anchorRotation"];
if (anchorRotation.isValid() && if (anchorRotation.isValid()) {
anchorRotation.property("x").isValid() && setAnchorRotation(quatFromVariant(anchorRotation));
anchorRotation.property("y").isValid() &&
anchorRotation.property("z").isValid() &&
anchorRotation.property("w").isValid()) {
glm::quat newRotation;
quatFromScriptValue(anchorRotation, newRotation);
setAnchorRotation(newRotation);
} }
QScriptValue anchorRotationBinding = properties.property("anchorRotationBinding"); auto anchorRotationBinding = properties["anchorRotationBinding"];
if (anchorRotationBinding.isValid()) { if (anchorRotationBinding.isValid()) {
PropertyBinding binding = {}; PropertyBinding binding = {};
propertyBindingFromScriptValue(anchorPositionBinding, binding); propertyBindingFromVariant(anchorPositionBinding, binding);
_anchorRotationBindMyAvatar = binding.avatar == "MyAvatar"; _anchorRotationBindMyAvatar = binding.avatar == "MyAvatar";
_anchorRotationBindEntity = binding.entity; _anchorRotationBindEntity = binding.entity;
} }
QScriptValue anchorScale = properties.property("anchorScale"); auto anchorScale = properties["anchorScale"];
if (anchorScale.isValid()) { if (anchorScale.isValid()) {
if (anchorScale.property("x").isValid() && setAnchorScale(vec3FromVariant(anchorScale));
anchorScale.property("y").isValid() &&
anchorScale.property("z").isValid()) {
glm::vec3 newScale;
vec3FromScriptValue(anchorScale, newScale);
setAnchorScale(newScale);
} else {
setAnchorScale(anchorScale.toVariant().toFloat());
}
} }
QScriptValue visible = properties.property("visible"); auto visible = properties["visible"];
if (visible.isValid()) { if (visible.isValid()) {
setVisible(visible.toVariant().toBool()); setVisible(visible.toBool());
} }
} }

View file

@ -16,7 +16,6 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include <QScriptValue>
#include <QUuid> #include <QUuid>
#include "PanelAttachable.h" #include "PanelAttachable.h"
@ -30,8 +29,8 @@ public:
QUuid entity; QUuid entity;
}; };
QScriptValue propertyBindingToScriptValue(QScriptEngine* engine, const PropertyBinding& value); QVariant propertyBindingToVariant(const PropertyBinding& value);
void propertyBindingFromScriptValue(const QScriptValue& object, PropertyBinding& value); void propertyBindingFromVariant(const QVariant& object, PropertyBinding& value);
class OverlayPanel : public QObject, public PanelAttachable, public Billboardable { class OverlayPanel : public QObject, public PanelAttachable, public Billboardable {
@ -60,8 +59,8 @@ public:
void removeChild(unsigned int childId); void removeChild(unsigned int childId);
unsigned int popLastChild() { return _children.takeLast(); } unsigned int popLastChild() { return _children.takeLast(); }
QScriptValue getProperty(const QString& property); void setProperties(const QVariantMap& properties);
void setProperties(const QScriptValue& properties); QVariant getProperty(const QString& property);
virtual void applyTransformTo(Transform& transform, bool force = false); virtual void applyTransformTo(Transform& transform, bool force = false);

View file

@ -153,7 +153,7 @@ Overlay::Pointer Overlays::getOverlay(unsigned int id) const {
return nullptr; return nullptr;
} }
unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& properties) { unsigned int Overlays::addOverlay(const QString& type, const QVariant& properties) {
Overlay::Pointer thisOverlay = nullptr; Overlay::Pointer thisOverlay = nullptr;
if (type == ImageOverlay::TYPE) { if (type == ImageOverlay::TYPE) {
@ -187,15 +187,13 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
} }
if (thisOverlay) { if (thisOverlay) {
thisOverlay->setProperties(properties); thisOverlay->setProperties(properties.toMap());
return addOverlay(thisOverlay); return addOverlay(thisOverlay);
} }
return 0; return 0;
} }
unsigned int Overlays::addOverlay(Overlay::Pointer overlay) { unsigned int Overlays::addOverlay(Overlay::Pointer overlay) {
overlay->init(_scriptEngine);
QWriteLocker lock(&_lock); QWriteLocker lock(&_lock);
unsigned int thisID = _nextOverlayID; unsigned int thisID = _nextOverlayID;
_nextOverlayID++; _nextOverlayID++;
@ -228,7 +226,7 @@ unsigned int Overlays::cloneOverlay(unsigned int id) {
return 0; // Not found return 0; // Not found
} }
bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) { bool Overlays::editOverlay(unsigned int id, const QVariant& properties) {
QWriteLocker lock(&_lock); QWriteLocker lock(&_lock);
Overlay::Pointer thisOverlay = getOverlay(id); Overlay::Pointer thisOverlay = getOverlay(id);
@ -236,7 +234,7 @@ bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
if (thisOverlay->is3D()) { if (thisOverlay->is3D()) {
render::ItemKey oldItemKey = render::payloadGetKey(thisOverlay); render::ItemKey oldItemKey = render::payloadGetKey(thisOverlay);
thisOverlay->setProperties(properties); thisOverlay->setProperties(properties.toMap());
render::ItemKey itemKey = render::payloadGetKey(thisOverlay); render::ItemKey itemKey = render::payloadGetKey(thisOverlay);
if (itemKey != oldItemKey) { if (itemKey != oldItemKey) {
@ -249,7 +247,7 @@ bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
} }
} }
} else { } else {
thisOverlay->setProperties(properties); thisOverlay->setProperties(properties.toMap());
} }
return true; return true;
@ -380,36 +378,21 @@ OverlayPropertyResult Overlays::getProperty(unsigned int id, const QString& prop
return result; return result;
} }
OverlayPropertyResult::OverlayPropertyResult() : OverlayPropertyResult::OverlayPropertyResult() {
value(QScriptValue())
{
} }
QScriptValue OverlayPropertyResultToScriptValue(QScriptEngine* engine, const OverlayPropertyResult& result) QScriptValue OverlayPropertyResultToScriptValue(QScriptEngine* engine, const OverlayPropertyResult& value) {
{ if (!value.value.isValid()) {
if (!result.value.isValid()) {
return QScriptValue::UndefinedValue; return QScriptValue::UndefinedValue;
} }
return engine->newVariant(value.value);
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) void OverlayPropertyResultFromScriptValue(const QScriptValue& object, OverlayPropertyResult& value) {
{ value.value = object.toVariant();
result.value = value;
} }
RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray) { RayToOverlayIntersectionResult Overlays::findRayIntersection(const PickRay& ray) {
float bestDistance = std::numeric_limits<float>::max(); float bestDistance = std::numeric_limits<float>::max();
bool bestIsFront = false; bool bestIsFront = false;
@ -456,7 +439,7 @@ RayToOverlayIntersectionResult::RayToOverlayIntersectionResult() :
} }
QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, const RayToOverlayIntersectionResult& value) { QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine, const RayToOverlayIntersectionResult& value) {
QScriptValue obj = engine->newObject(); auto obj = engine->newObject();
obj.setProperty("intersects", value.intersects); obj.setProperty("intersects", value.intersects);
obj.setProperty("overlayID", value.overlayID); obj.setProperty("overlayID", value.overlayID);
obj.setProperty("distance", value.distance); obj.setProperty("distance", value.distance);
@ -488,18 +471,19 @@ QScriptValue RayToOverlayIntersectionResultToScriptValue(QScriptEngine* engine,
break; break;
} }
obj.setProperty("face", faceName); obj.setProperty("face", faceName);
QScriptValue intersection = vec3toScriptValue(engine, value.intersection); auto intersection = vec3toScriptValue(engine, value.intersection);
obj.setProperty("intersection", intersection); obj.setProperty("intersection", intersection);
obj.setProperty("extraInfo", value.extraInfo); obj.setProperty("extraInfo", value.extraInfo);
return obj; return obj;
} }
void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, RayToOverlayIntersectionResult& value) { void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& objectVar, RayToOverlayIntersectionResult& value) {
value.intersects = object.property("intersects").toVariant().toBool(); QVariantMap object = objectVar.toVariant().toMap();
value.overlayID = object.property("overlayID").toVariant().toInt(); value.intersects = object["intersects"].toBool();
value.distance = object.property("distance").toVariant().toFloat(); value.overlayID = object["overlayID"].toInt();
value.distance = object["distance"].toFloat();
QString faceName = object.property("face").toVariant().toString(); QString faceName = object["face"].toString();
if (faceName == "MIN_X_FACE") { if (faceName == "MIN_X_FACE") {
value.face = MIN_X_FACE; value.face = MIN_X_FACE;
} else if (faceName == "MAX_X_FACE") { } else if (faceName == "MAX_X_FACE") {
@ -515,11 +499,15 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R
} else { } else {
value.face = UNKNOWN_FACE; value.face = UNKNOWN_FACE;
}; };
QScriptValue intersection = object.property("intersection"); auto intersection = object["intersection"];
if (intersection.isValid()) { if (intersection.isValid()) {
vec3FromScriptValue(intersection, value.intersection); bool valid;
auto newIntersection = vec3FromVariant(intersection, valid);
if (valid) {
value.intersection = newIntersection;
}
} }
value.extraInfo = object.property("extraInfo").toVariant().toString(); value.extraInfo = object["extraInfo"].toString();
} }
bool Overlays::isLoaded(unsigned int id) { bool Overlays::isLoaded(unsigned int id) {
@ -556,16 +544,16 @@ unsigned int Overlays::addPanel(OverlayPanel::Pointer panel) {
return thisID; return thisID;
} }
unsigned int Overlays::addPanel(const QScriptValue& properties) { unsigned int Overlays::addPanel(const QVariant& properties) {
OverlayPanel::Pointer panel = std::make_shared<OverlayPanel>(); OverlayPanel::Pointer panel = std::make_shared<OverlayPanel>();
panel->init(_scriptEngine); panel->init(_scriptEngine);
panel->setProperties(properties); panel->setProperties(properties.toMap());
return addPanel(panel); return addPanel(panel);
} }
void Overlays::editPanel(unsigned int panelId, const QScriptValue& properties) { void Overlays::editPanel(unsigned int panelId, const QVariant& properties) {
if (_panels.contains(panelId)) { if (_panels.contains(panelId)) {
_panels[panelId]->setProperties(properties); _panels[panelId]->setProperties(properties.toMap());
} }
} }

View file

@ -31,7 +31,7 @@ class PickRay;
class OverlayPropertyResult { class OverlayPropertyResult {
public: public:
OverlayPropertyResult(); OverlayPropertyResult();
QScriptValue value; QVariant value;
}; };
Q_DECLARE_METATYPE(OverlayPropertyResult); Q_DECLARE_METATYPE(OverlayPropertyResult);
@ -75,7 +75,7 @@ public:
public slots: public slots:
/// adds an overlay with the specific properties /// adds an overlay with the specific properties
unsigned int addOverlay(const QString& type, const QScriptValue& properties); unsigned int addOverlay(const QString& type, const QVariant& properties);
/// adds an overlay that's already been created /// adds an overlay that's already been created
unsigned int addOverlay(Overlay* overlay) { return addOverlay(Overlay::Pointer(overlay)); } unsigned int addOverlay(Overlay* overlay) { return addOverlay(Overlay::Pointer(overlay)); }
@ -86,7 +86,7 @@ public slots:
/// edits an overlay updating only the included properties, will return the identified OverlayID in case of /// edits an overlay updating only the included properties, will return the identified OverlayID in case of
/// successful edit, if the input id is for an unknown overlay this function will have no effect /// successful edit, if the input id is for an unknown overlay this function will have no effect
bool editOverlay(unsigned int id, const QScriptValue& properties); bool editOverlay(unsigned int id, const QVariant& properties);
/// deletes a particle /// deletes a particle
void deleteOverlay(unsigned int id); void deleteOverlay(unsigned int id);
@ -122,10 +122,10 @@ public slots:
unsigned int addPanel(OverlayPanel::Pointer panel); unsigned int addPanel(OverlayPanel::Pointer panel);
/// creates and adds a panel based on a set of properties /// creates and adds a panel based on a set of properties
unsigned int addPanel(const QScriptValue& properties); unsigned int addPanel(const QVariant& properties);
/// edit the properties of a panel /// edit the properties of a panel
void editPanel(unsigned int panelId, const QScriptValue& properties); void editPanel(unsigned int panelId, const QVariant& properties);
/// get a property of a panel /// get a property of a panel
OverlayPropertyResult getPanelProperty(unsigned int panelId, const QString& property); OverlayPropertyResult getPanelProperty(unsigned int panelId, const QString& property);

View file

@ -8,8 +8,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <QScriptValueIterator>
#include <limits> #include <limits>
#include <typeinfo> #include <typeinfo>

View file

@ -23,53 +23,38 @@ bool PanelAttachable::getParentVisible() const {
} }
} }
QScriptValue PanelAttachable::getProperty(QScriptEngine* scriptEngine, const QString &property) { QVariant PanelAttachable::getProperty(const QString& property) {
if (property == "offsetPosition") { if (property == "offsetPosition") {
return vec3toScriptValue(scriptEngine, getOffsetPosition()); return vec3toVariant(getOffsetPosition());
} }
if (property == "offsetRotation") { if (property == "offsetRotation") {
return quatToScriptValue(scriptEngine, getOffsetRotation()); return quatToVariant(getOffsetRotation());
} }
if (property == "offsetScale") { if (property == "offsetScale") {
return vec3toScriptValue(scriptEngine, getOffsetScale()); return vec3toVariant(getOffsetScale());
} }
return QScriptValue(); return QVariant();
} }
void PanelAttachable::setProperties(const QScriptValue &properties) { void PanelAttachable::setProperties(const QVariantMap& properties) {
QScriptValue offsetPosition = properties.property("offsetPosition"); auto offsetPosition = properties["offsetPosition"];
if (offsetPosition.isValid() && bool valid;
offsetPosition.property("x").isValid() && if (offsetPosition.isValid()) {
offsetPosition.property("y").isValid() && glm::vec3 newPosition = vec3FromVariant(offsetPosition, valid);
offsetPosition.property("z").isValid()) { if (valid) {
glm::vec3 newPosition; setOffsetPosition(newPosition);
vec3FromScriptValue(offsetPosition, newPosition);
setOffsetPosition(newPosition);
}
QScriptValue offsetRotation = properties.property("offsetRotation");
if (offsetRotation.isValid() &&
offsetRotation.property("x").isValid() &&
offsetRotation.property("y").isValid() &&
offsetRotation.property("z").isValid() &&
offsetRotation.property("w").isValid()) {
glm::quat newRotation;
quatFromScriptValue(offsetRotation, newRotation);
setOffsetRotation(newRotation);
}
QScriptValue offsetScale = properties.property("offsetScale");
if (offsetScale.isValid()) {
if (offsetScale.property("x").isValid() &&
offsetScale.property("y").isValid() &&
offsetScale.property("z").isValid()) {
glm::vec3 newScale;
vec3FromScriptValue(offsetScale, newScale);
setOffsetScale(newScale);
} else {
setOffsetScale(offsetScale.toVariant().toFloat());
} }
} }
auto offsetRotation = properties["offsetRotation"];
if (offsetRotation.isValid()) {
setOffsetRotation(quatFromVariant(offsetRotation));
}
auto offsetScale = properties["offsetScale"];
if (offsetScale.isValid()) {
setOffsetScale(vec3FromVariant(offsetScale));
}
} }
void PanelAttachable::applyTransformTo(Transform& transform, bool force) { void PanelAttachable::applyTransformTo(Transform& transform, bool force) {

View file

@ -57,8 +57,8 @@ public:
void setOffsetScale(const glm::vec3& scale) { _offset.setScale(scale); } void setOffsetScale(const glm::vec3& scale) { _offset.setScale(scale); }
protected: protected:
QScriptValue getProperty(QScriptEngine* scriptEngine, const QString& property); void setProperties(const QVariantMap& properties);
void setProperties(const QScriptValue& properties); QVariant getProperty(const QString& property);
/// set position, rotation and scale on transform based on offsets, and parent panel offsets /// set position, rotation and scale on transform based on offsets, and parent panel offsets
/// if force is false, only apply transform if it hasn't been applied in the last .1 seconds /// if force is false, only apply transform if it hasn't been applied in the last .1 seconds

View file

@ -35,57 +35,27 @@ AABox Planar3DOverlay::getBounds() const {
return AABox(extents); return AABox(extents);
} }
void Planar3DOverlay::setProperties(const QScriptValue& properties) { void Planar3DOverlay::setProperties(const QVariantMap& properties) {
Base3DOverlay::setProperties(properties); Base3DOverlay::setProperties(properties);
QScriptValue dimensions = properties.property("dimensions"); auto dimensions = properties["dimensions"];
// if "dimensions" property was not there, check to see if they included aliases: scale // if "dimensions" property was not there, check to see if they included aliases: scale
if (!dimensions.isValid()) { if (!dimensions.isValid()) {
dimensions = properties.property("scale"); dimensions = properties["scale"];
if (!dimensions.isValid()) { if (!dimensions.isValid()) {
dimensions = properties.property("size"); dimensions = properties["size"];
} }
} }
if (dimensions.isValid()) { if (dimensions.isValid()) {
bool validDimensions = false; setDimensions(vec2FromVariant(dimensions));
glm::vec2 newDimensions;
QScriptValue x = dimensions.property("x");
QScriptValue y = dimensions.property("y");
if (x.isValid() && y.isValid()) {
newDimensions.x = x.toVariant().toFloat();
newDimensions.y = y.toVariant().toFloat();
validDimensions = true;
} else {
QScriptValue width = dimensions.property("width");
QScriptValue height = dimensions.property("height");
if (width.isValid() && height.isValid()) {
newDimensions.x = width.toVariant().toFloat();
newDimensions.y = height.toVariant().toFloat();
validDimensions = true;
}
}
// size, scale, dimensions is special, it might just be a single scalar, check that here
if (!validDimensions && dimensions.isNumber()) {
float size = dimensions.toVariant().toFloat();
newDimensions.x = size;
newDimensions.y = size;
validDimensions = true;
}
if (validDimensions) {
setDimensions(newDimensions);
}
} }
} }
QScriptValue Planar3DOverlay::getProperty(const QString& property) { QVariant Planar3DOverlay::getProperty(const QString& property) {
if (property == "dimensions" || property == "scale" || property == "size") { if (property == "dimensions" || property == "scale" || property == "size") {
return vec2toScriptValue(_scriptEngine, getDimensions()); return vec2toVariant(getDimensions());
} }
return Base3DOverlay::getProperty(property); return Base3DOverlay::getProperty(property);

View file

@ -26,8 +26,8 @@ public:
void setDimensions(float value) { _dimensions = glm::vec2(value); } void setDimensions(float value) { _dimensions = glm::vec2(value); }
void setDimensions(const glm::vec2& value) { _dimensions = value; } void setDimensions(const glm::vec2& value) { _dimensions = value; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);

View file

@ -57,7 +57,7 @@ QmlOverlay::~QmlOverlay() {
} }
} }
void QmlOverlay::setProperties(const QScriptValue& properties) { void QmlOverlay::setProperties(const QVariantMap& properties) {
Overlay2D::setProperties(properties); Overlay2D::setProperties(properties);
auto bounds = _bounds; auto bounds = _bounds;
std::weak_ptr<QQuickItem> weakQmlElement; std::weak_ptr<QQuickItem> weakQmlElement;
@ -71,7 +71,7 @@ void QmlOverlay::setProperties(const QScriptValue& properties) {
_qmlElement->setHeight(bounds.height()); _qmlElement->setHeight(bounds.height());
} }
}); });
QMetaObject::invokeMethod(_qmlElement.get(), "updatePropertiesFromScript", Q_ARG(QVariant, properties.toVariant())); QMetaObject::invokeMethod(_qmlElement.get(), "updatePropertiesFromScript", Q_ARG(QVariant, properties));
} }
void QmlOverlay::render(RenderArgs* args) { void QmlOverlay::render(RenderArgs* args) {

View file

@ -28,7 +28,7 @@ public:
// Cannot fetch properties from QML based overlays due to race conditions // Cannot fetch properties from QML based overlays due to race conditions
bool supportsGetProperty() const override { return false; } bool supportsGetProperty() const override { return false; }
void setProperties(const QScriptValue& properties) override; void setProperties(const QVariantMap& properties) override;
void render(RenderArgs* args) override; void render(RenderArgs* args) override;
private: private:

View file

@ -96,7 +96,7 @@ const render::ShapeKey Rectangle3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Rectangle3DOverlay::setProperties(const QScriptValue &properties) { void Rectangle3DOverlay::setProperties(const QVariantMap& properties) {
Planar3DOverlay::setProperties(properties); Planar3DOverlay::setProperties(properties);
} }

View file

@ -25,7 +25,7 @@ public:
~Rectangle3DOverlay(); ~Rectangle3DOverlay();
virtual void render(RenderArgs* args); virtual void render(RenderArgs* args);
virtual const render::ShapeKey getShapeKey() override; virtual const render::ShapeKey getShapeKey() override;
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual Rectangle3DOverlay* createClone() const; virtual Rectangle3DOverlay* createClone() const;
private: private:

View file

@ -121,57 +121,54 @@ const render::ShapeKey Text3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Text3DOverlay::setProperties(const QScriptValue& properties) { void Text3DOverlay::setProperties(const QVariantMap& properties) {
Billboard3DOverlay::setProperties(properties); Billboard3DOverlay::setProperties(properties);
QScriptValue text = properties.property("text"); auto text = properties["text"];
if (text.isValid()) { if (text.isValid()) {
setText(text.toVariant().toString()); setText(text.toString());
} }
QScriptValue textAlpha = properties.property("textAlpha"); auto textAlpha = properties["textAlpha"];
if (textAlpha.isValid()) { if (textAlpha.isValid()) {
setTextAlpha(textAlpha.toVariant().toFloat()); setTextAlpha(textAlpha.toFloat());
} }
QScriptValue backgroundColor = properties.property("backgroundColor"); bool valid;
auto backgroundColor = properties["backgroundColor"];
if (backgroundColor.isValid()) { if (backgroundColor.isValid()) {
QScriptValue red = backgroundColor.property("red"); auto color = xColorFromVariant(backgroundColor, valid);
QScriptValue green = backgroundColor.property("green"); if (valid) {
QScriptValue blue = backgroundColor.property("blue"); _backgroundColor = color;
if (red.isValid() && green.isValid() && blue.isValid()) {
_backgroundColor.red = red.toVariant().toInt();
_backgroundColor.green = green.toVariant().toInt();
_backgroundColor.blue = blue.toVariant().toInt();
} }
} }
if (properties.property("backgroundAlpha").isValid()) { if (properties["backgroundAlpha"].isValid()) {
setAlpha(properties.property("backgroundAlpha").toVariant().toFloat()); setAlpha(properties["backgroundAlpha"].toFloat());
} }
if (properties.property("lineHeight").isValid()) { if (properties["lineHeight"].isValid()) {
setLineHeight(properties.property("lineHeight").toVariant().toFloat()); setLineHeight(properties["lineHeight"].toFloat());
} }
if (properties.property("leftMargin").isValid()) { if (properties["leftMargin"].isValid()) {
setLeftMargin(properties.property("leftMargin").toVariant().toFloat()); setLeftMargin(properties["leftMargin"].toFloat());
} }
if (properties.property("topMargin").isValid()) { if (properties["topMargin"].isValid()) {
setTopMargin(properties.property("topMargin").toVariant().toFloat()); setTopMargin(properties["topMargin"].toFloat());
} }
if (properties.property("rightMargin").isValid()) { if (properties["rightMargin"].isValid()) {
setRightMargin(properties.property("rightMargin").toVariant().toFloat()); setRightMargin(properties["rightMargin"].toFloat());
} }
if (properties.property("bottomMargin").isValid()) { if (properties["bottomMargin"].isValid()) {
setBottomMargin(properties.property("bottomMargin").toVariant().toFloat()); setBottomMargin(properties["bottomMargin"].toFloat());
} }
} }
QScriptValue Text3DOverlay::getProperty(const QString& property) { QVariant Text3DOverlay::getProperty(const QString& property) {
if (property == "text") { if (property == "text") {
return _text; return _text;
} }
@ -179,7 +176,7 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
return _textAlpha; return _textAlpha;
} }
if (property == "backgroundColor") { if (property == "backgroundColor") {
return xColorToScriptValue(_scriptEngine, _backgroundColor); return xColorToVariant(_backgroundColor);
} }
if (property == "backgroundAlpha") { if (property == "backgroundAlpha") {
return Billboard3DOverlay::getProperty("alpha"); return Billboard3DOverlay::getProperty("alpha");

View file

@ -53,8 +53,8 @@ public:
void setRightMargin(float margin) { _rightMargin = margin; } void setRightMargin(float margin) { _rightMargin = margin; }
void setBottomMargin(float margin) { _bottomMargin = margin; } void setBottomMargin(float margin) { _bottomMargin = margin; }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
QSizeF textSize(const QString& test) const; // Meters QSizeF textSize(const QString& test) const; // Meters

View file

@ -26,67 +26,27 @@ AABox Volume3DOverlay::getBounds() const {
return AABox(extents); return AABox(extents);
} }
void Volume3DOverlay::setProperties(const QScriptValue& properties) { void Volume3DOverlay::setProperties(const QVariantMap& properties) {
Base3DOverlay::setProperties(properties); Base3DOverlay::setProperties(properties);
QScriptValue dimensions = properties.property("dimensions"); auto dimensions = properties["dimensions"];
// if "dimensions" property was not there, check to see if they included aliases: scale // if "dimensions" property was not there, check to see if they included aliases: scale
if (!dimensions.isValid()) { if (!dimensions.isValid()) {
dimensions = properties.property("scale"); dimensions = properties["scale"];
if (!dimensions.isValid()) { if (!dimensions.isValid()) {
dimensions = properties.property("size"); dimensions = properties["size"];
} }
} }
if (dimensions.isValid()) { if (dimensions.isValid()) {
bool validDimensions = false; setDimensions(vec3FromVariant(dimensions));
glm::vec3 newDimensions;
QScriptValue x = dimensions.property("x");
QScriptValue y = dimensions.property("y");
QScriptValue z = dimensions.property("z");
if (x.isValid() && x.isNumber() &&
y.isValid() && y.isNumber() &&
z.isValid() && z.isNumber()) {
newDimensions.x = x.toNumber();
newDimensions.y = y.toNumber();
newDimensions.z = z.toNumber();
validDimensions = true;
} else {
QScriptValue width = dimensions.property("width");
QScriptValue height = dimensions.property("height");
QScriptValue depth = dimensions.property("depth");
if (width.isValid() && width.isNumber() &&
height.isValid() && height.isNumber() &&
depth.isValid() && depth.isNumber()) {
newDimensions.x = width.toNumber();
newDimensions.y = height.toNumber();
newDimensions.z = depth.toNumber();
validDimensions = true;
}
}
// size, scale, dimensions is special, it might just be a single scalar, check that here
if (!validDimensions && dimensions.isNumber()) {
float size = dimensions.toNumber();
newDimensions.x = size;
newDimensions.y = size;
newDimensions.z = size;
validDimensions = true;
}
if (validDimensions) {
setDimensions(newDimensions);
}
} }
} }
QScriptValue Volume3DOverlay::getProperty(const QString& property) { QVariant Volume3DOverlay::getProperty(const QString& property) {
if (property == "dimensions" || property == "scale" || property == "size") { if (property == "dimensions" || property == "scale" || property == "size") {
return vec3toScriptValue(_scriptEngine, getDimensions()); return vec3toVariant(getDimensions());
} }
return Base3DOverlay::getProperty(property); return Base3DOverlay::getProperty(property);

View file

@ -26,8 +26,8 @@ public:
void setDimensions(float value) { _localBoundingBox.setBox(glm::vec3(-value / 2.0f), value); } void setDimensions(float value) { _localBoundingBox.setBox(glm::vec3(-value / 2.0f), value); }
void setDimensions(const glm::vec3& value) { _localBoundingBox.setBox(-value / 2.0f, value); } void setDimensions(const glm::vec3& value) { _localBoundingBox.setBox(-value / 2.0f, value); }
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);

View file

@ -12,7 +12,6 @@
#include "Web3DOverlay.h" #include "Web3DOverlay.h"
#include <QtScript/QScriptValue>
#include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLContext>
#include <QtQuick/QQuickItem> #include <QtQuick/QQuickItem>
@ -113,30 +112,34 @@ const render::ShapeKey Web3DOverlay::getShapeKey() {
return builder.build(); return builder.build();
} }
void Web3DOverlay::setProperties(const QScriptValue &properties) { void Web3DOverlay::setProperties(const QVariantMap& properties) {
Billboard3DOverlay::setProperties(properties); Billboard3DOverlay::setProperties(properties);
QScriptValue urlValue = properties.property("url"); auto urlValue = properties["url"];
if (urlValue.isValid()) { if (urlValue.isValid()) {
QString newURL = urlValue.toVariant().toString(); QString newURL = urlValue.toString();
if (newURL != _url) { if (newURL != _url) {
setURL(newURL); setURL(newURL);
} }
} }
QScriptValue resolution = properties.property("resolution"); auto resolution = properties["resolution"];
if (resolution.isValid()) { if (resolution.isValid()) {
vec2FromScriptValue(resolution, _resolution); bool valid;
auto res = vec2FromVariant(resolution, valid);
if (valid) {
_resolution = res;
}
} }
QScriptValue dpi = properties.property("dpi"); auto dpi = properties["dpi"];
if (dpi.isValid()) { if (dpi.isValid()) {
_dpi = dpi.toVariant().toFloat(); _dpi = dpi.toFloat();
} }
} }
QScriptValue Web3DOverlay::getProperty(const QString& property) { QVariant Web3DOverlay::getProperty(const QString& property) {
if (property == "url") { if (property == "url") {
return _url; return _url;
} }

View file

@ -32,8 +32,8 @@ public:
// setters // setters
void setURL(const QString& url); void setURL(const QString& url);
virtual void setProperties(const QScriptValue& properties); void setProperties(const QVariantMap& properties) override;
virtual QScriptValue getProperty(const QString& property); QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal);

View file

@ -14,6 +14,7 @@
#include <QtCore/QRect> #include <QtCore/QRect>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtGui/QColor> #include <QtGui/QColor>
#include <QtGui/QVector2D>
#include <QtGui/QVector3D> #include <QtGui/QVector3D>
#include <QtGui/QQuaternion> #include <QtGui/QQuaternion>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
@ -86,6 +87,19 @@ void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3) {
vec3.z = object.property("z").toVariant().toFloat(); vec3.z = object.property("z").toVariant().toFloat();
} }
QVariant vec3toVariant(const glm::vec3 &vec3) {
if (vec3.x != vec3.x || vec3.y != vec3.y || vec3.z != vec3.z) {
// if vec3 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec3.x;
result["y"] = vec3.y;
result["z"] = vec3.z;
return result;
}
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector) { QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector) {
QScriptValue array = engine->newArray(); QScriptValue array = engine->newArray();
for (int i = 0; i < vector.size(); i++) { for (int i = 0; i < vector.size(); i++) {
@ -94,6 +108,7 @@ QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::
return array; return array;
} }
glm::vec3 vec3FromVariant(const QVariant &object, bool& valid) { glm::vec3 vec3FromVariant(const QVariant &object, bool& valid) {
glm::vec3 v; glm::vec3 v;
valid = false; valid = false;
@ -138,7 +153,6 @@ glm::vec3 vec3FromVariant(const QVariant &object) {
return vec3FromVariant(object, valid); return vec3FromVariant(object, valid);
} }
QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat &quat) { QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat &quat) {
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z || quat.w != quat.w) { if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z || quat.w != quat.w) {
@ -195,6 +209,19 @@ glm::quat quatFromVariant(const QVariant &object) {
return quatFromVariant(object, valid); return quatFromVariant(object, valid);
} }
QVariant quatToVariant(const glm::quat &quat) {
if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z) {
// if vec3 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = quat.x;
result["y"] = quat.y;
result["z"] = quat.z;
result["w"] = quat.w;
return result;
}
QScriptValue qVectorQuatToScriptValue(QScriptEngine* engine, const QVector<glm::quat>& vector) { QScriptValue qVectorQuatToScriptValue(QScriptEngine* engine, const QVector<glm::quat>& vector) {
QScriptValue array = engine->newArray(); QScriptValue array = engine->newArray();
for (int i = 0; i < vector.size(); i++) { for (int i = 0; i < vector.size(); i++) {
@ -333,6 +360,51 @@ void vec2FromScriptValue(const QScriptValue &object, glm::vec2 &vec2) {
vec2.y = object.property("y").toVariant().toFloat(); vec2.y = object.property("y").toVariant().toFloat();
} }
QVariant vec2toVariant(const glm::vec2 &vec2) {
if (vec2.x != vec2.x || vec2.y != vec2.y) {
// if vec2 contains a NaN don't try to convert it
return QVariant();
}
QVariantMap result;
result["x"] = vec2.x;
result["y"] = vec2.y;
return result;
}
glm::vec2 vec2FromVariant(const QVariant &object, bool& isValid) {
isValid = false;
glm::vec2 result;
if (object.canConvert<float>()) {
result = glm::vec2(object.toFloat());
} else if (object.canConvert<QVector2D>()) {
auto qvec2 = qvariant_cast<QVector2D>(object);
result.x = qvec2.x();
result.y = qvec2.y();
} else {
auto map = object.toMap();
auto x = map["x"];
if (!x.isValid()) {
x = map["width"];
}
auto y = map["y"];
if (!y.isValid()) {
y = map["height"];
}
if (x.isValid() && y.isValid()) {
result.x = x.toFloat(&isValid);
if (isValid) {
result.y = y.toFloat(&isValid);
}
}
}
return result;
}
glm::vec2 vec2FromVariant(const QVariant &object) {
bool valid;
return vec2FromVariant(object, valid);
}
QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect) { QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect) {
QScriptValue obj = engine->newObject(); QScriptValue obj = engine->newObject();
obj.setProperty("x", rect.x()); obj.setProperty("x", rect.x());
@ -357,6 +429,38 @@ QScriptValue xColorToScriptValue(QScriptEngine *engine, const xColor& color) {
return obj; return obj;
} }
QVariant qRectToVariant(const QRect& rect) {
QVariantMap obj;
obj["x"] = rect.x();
obj["y"] = rect.y();
obj["width"] = rect.width();
obj["height"] = rect.height();
return obj;
}
QRect qRectFromVariant(const QVariant& objectVar, bool& valid) {
QVariantMap object = objectVar.toMap();
QRect rect;
valid = false;
rect.setX(object["x"].toInt(&valid));
if (valid) {
rect.setY(object["y"].toInt(&valid));
}
if (valid) {
rect.setWidth(object["width"].toInt(&valid));
}
if (valid) {
rect.setHeight(object["height"].toInt(&valid));
}
return rect;
}
QRect qRectFromVariant(const QVariant& object) {
bool valid;
return qRectFromVariant(object, valid);
}
void xColorFromScriptValue(const QScriptValue &object, xColor& color) { void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
if (!object.isValid()) { if (!object.isValid()) {
return; return;
@ -377,6 +481,59 @@ void xColorFromScriptValue(const QScriptValue &object, xColor& color) {
} }
} }
QVariant xColorToVariant(const xColor& color) {
QVariantMap obj;
obj["red"] = color.red;
obj["green"] = color.green;
obj["blue"] = color.blue;
return obj;
}
xColor xColorFromVariant(const QVariant &object, bool& isValid) {
isValid = false;
xColor color { 0, 0, 0 };
if (!object.isValid()) {
return color;
}
if (object.canConvert<int>()) {
isValid = true;
color.red = color.green = color.blue = (uint8_t)object.toInt();
} else if (object.canConvert<QString>()) {
QColor qcolor(object.toString());
if (qcolor.isValid()) {
isValid = true;
color.red = (uint8_t)qcolor.red();
color.blue = (uint8_t)qcolor.blue();
color.green = (uint8_t)qcolor.green();
}
} else if (object.canConvert<QColor>()) {
QColor qcolor = qvariant_cast<QColor>(object);
if (qcolor.isValid()) {
isValid = true;
color.red = (uint8_t)qcolor.red();
color.blue = (uint8_t)qcolor.blue();
color.green = (uint8_t)qcolor.green();
}
} else {
QVariantMap map = object.toMap();
color.red = map["red"].toInt(&isValid);
if (isValid) {
color.green = map["green"].toInt(&isValid);
}
if (isValid) {
color.blue = map["blue"].toInt(&isValid);
}
}
return color;
}
xColor xColorFromVariant(const QVariant &object) {
bool valid;
return xColorFromVariant(object, valid);
}
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) { QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color) {
QScriptValue object = engine->newObject(); QScriptValue object = engine->newObject();
object.setProperty("red", color.red()); object.setProperty("red", color.red());

View file

@ -35,48 +35,71 @@ Q_DECLARE_METATYPE(AACube)
void registerMetaTypes(QScriptEngine* engine); void registerMetaTypes(QScriptEngine* engine);
// Vec4
QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4); QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4);
void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4); void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4);
// Vec3
QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3); QScriptValue vec3toScriptValue(QScriptEngine* engine, const glm::vec3 &vec3);
void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3); void vec3FromScriptValue(const QScriptValue &object, glm::vec3 &vec3);
QVariant vec3toVariant(const glm::vec3 &vec3);
glm::vec3 vec3FromVariant(const QVariant &object, bool& valid); glm::vec3 vec3FromVariant(const QVariant &object, bool& valid);
glm::vec3 vec3FromVariant(const QVariant &object); glm::vec3 vec3FromVariant(const QVariant &object);
// Vec2
QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2); QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2);
void vec2FromScriptValue(const QScriptValue &object, glm::vec2 &vec2); void vec2FromScriptValue(const QScriptValue &object, glm::vec2 &vec2);
QVariant vec2toVariant(const glm::vec2 &vec2);
glm::vec2 vec2FromVariant(const QVariant &object, bool& valid);
glm::vec2 vec2FromVariant(const QVariant &object);
// Quaternions
QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat& quat); QScriptValue quatToScriptValue(QScriptEngine* engine, const glm::quat& quat);
void quatFromScriptValue(const QScriptValue &object, glm::quat& quat); void quatFromScriptValue(const QScriptValue &object, glm::quat& quat);
QVariant quatToVariant(const glm::quat& quat);
glm::quat quatFromVariant(const QVariant &object, bool& isValid); glm::quat quatFromVariant(const QVariant &object, bool& isValid);
glm::quat quatFromVariant(const QVariant &object); glm::quat quatFromVariant(const QVariant &object);
// Rect
QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect); QScriptValue qRectToScriptValue(QScriptEngine* engine, const QRect& rect);
void qRectFromScriptValue(const QScriptValue& object, QRect& rect); void qRectFromScriptValue(const QScriptValue& object, QRect& rect);
QVariant qRectToVariant(const QRect& rect);
QRect qRectFromVariant(const QVariant& object, bool& isValid);
// xColor
QScriptValue xColorToScriptValue(QScriptEngine* engine, const xColor& color); QScriptValue xColorToScriptValue(QScriptEngine* engine, const xColor& color);
void xColorFromScriptValue(const QScriptValue &object, xColor& color); void xColorFromScriptValue(const QScriptValue &object, xColor& color);
QVariant xColorToVariant(const xColor& color);
xColor xColorFromVariant(const QVariant &object, bool& isValid);
// QColor
QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color); QScriptValue qColorToScriptValue(QScriptEngine* engine, const QColor& color);
void qColorFromScriptValue(const QScriptValue& object, QColor& color); void qColorFromScriptValue(const QScriptValue& object, QColor& color);
QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url); QScriptValue qURLToScriptValue(QScriptEngine* engine, const QUrl& url);
void qURLFromScriptValue(const QScriptValue& object, QUrl& url); void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
// vector<vec3>
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector); QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector);
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<glm::vec3>& vector); void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<glm::vec3>& vector);
QVector<glm::vec3> qVectorVec3FromScriptValue(const QScriptValue& array); QVector<glm::vec3> qVectorVec3FromScriptValue(const QScriptValue& array);
// vector<quat>
QScriptValue qVectorQuatToScriptValue(QScriptEngine* engine, const QVector<glm::quat>& vector); QScriptValue qVectorQuatToScriptValue(QScriptEngine* engine, const QVector<glm::quat>& vector);
void qVectorQuatFromScriptValue(const QScriptValue& array, QVector<glm::quat>& vector); void qVectorQuatFromScriptValue(const QScriptValue& array, QVector<glm::quat>& vector);
QVector<glm::quat> qVectorQuatFromScriptValue(const QScriptValue& array); QVector<glm::quat> qVectorQuatFromScriptValue(const QScriptValue& array);
// vector<bool>
QScriptValue qVectorBoolToScriptValue(QScriptEngine* engine, const QVector<bool>& vector); QScriptValue qVectorBoolToScriptValue(QScriptEngine* engine, const QVector<bool>& vector);
void qVectorBoolFromScriptValue(const QScriptValue& array, QVector<bool>& vector); void qVectorBoolFromScriptValue(const QScriptValue& array, QVector<bool>& vector);
QVector<bool> qVectorBoolFromScriptValue(const QScriptValue& array); QVector<bool> qVectorBoolFromScriptValue(const QScriptValue& array);
// vector<float>
QScriptValue qVectorFloatToScriptValue(QScriptEngine* engine, const QVector<float>& vector); QScriptValue qVectorFloatToScriptValue(QScriptEngine* engine, const QVector<float>& vector);
void qVectorFloatFromScriptValue(const QScriptValue& array, QVector<float>& vector); void qVectorFloatFromScriptValue(const QScriptValue& array, QVector<float>& vector);
QVector<float> qVectorFloatFromScriptValue(const QScriptValue& array); QVector<float> qVectorFloatFromScriptValue(const QScriptValue& array);