Refactor inheritance for billboard overlays.

BillboardOverlays is now Image3DOverlay.  Billboard3DOverlay is the base
class for both Image3DOverlay and Text3DOverlay, and it is
PanelAttachable.
This commit is contained in:
Zander Otavka 2015-08-04 12:04:13 -07:00
parent e5a429e8a6
commit 055133b82e
19 changed files with 218 additions and 161 deletions

View file

@ -30,7 +30,7 @@ var panel = new FloatingUIPanel({
facingRotation: { w: 0, x: 0, y: 1, z: 0 }
});
var background = new BillboardOverlay({
var background = new Image3DOverlay({
url: BG_IMAGE_URL,
dimensions: {
x: 0.5,
@ -42,7 +42,7 @@ var background = new BillboardOverlay({
});
panel.addChild(background);
var closeButton = new BillboardOverlay({
var closeButton = new Image3DOverlay({
url: CLOSE_IMAGE_URL,
dimensions: {
x: 0.15,
@ -62,7 +62,7 @@ closeButton.onClick = function(event) {
};
panel.addChild(closeButton);
var micMuteButton = new BillboardOverlay({
var micMuteButton = new Image3DOverlay({
url: MIC_IMAGE_URL,
subImage: {
x: 0,
@ -88,7 +88,7 @@ micMuteButton.onClick = function(event) {
};
panel.addChild(micMuteButton);
var faceMuteButton = new BillboardOverlay({
var faceMuteButton = new Image3DOverlay({
url: FACE_IMAGE_URL,
subImage: {
x: 0,
@ -114,7 +114,7 @@ faceMuteButton.onClick = function(event) {
};
panel.addChild(faceMuteButton);
var addressBarButton = new BillboardOverlay({
var addressBarButton = new Image3DOverlay({
url: ADDRESS_BAR_IMAGE_URL,
subImage: {
x: 0,

View file

@ -178,7 +178,7 @@
modelProperties.sittingPoints[seatIndex].rotation);
this.scale = MyAvatar.scale / 3;
this.sphere = Overlays.addOverlay("billboard", {
this.sphere = Overlays.addOverlay("image3d", {
subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight},
url: buttonImageUrl,
position: this.position,

View file

@ -252,7 +252,7 @@ function SpriteBillboard(sprite_properties, overlay) {
}
var christmastree_loader = null;
christmastree_loader = new OverlayPreloader("billboard",
christmastree_loader = new OverlayPreloader("image3d",
{url: CHRISTMAS_TREE_SPRITES_URL, alpha: 0}, function() {
for (var i = 0; i < NUM_OF_TREES; i++) {
var clonedOverlay = Overlays.cloneOverlay(christmastree_loader.overlay);
@ -269,7 +269,7 @@ christmastree_loader = new OverlayPreloader("billboard",
);
var santa_loader = null;
santa_loader = new OverlayPreloader("billboard",
santa_loader = new OverlayPreloader("image3d",
{url: SANTA_SPRITES_URL, alpha: 0}, function() {
for (var i = 0; i < NUM_OF_SANTAS; i++) {
var clonedOverlay = Overlays.cloneOverlay(santa_loader.overlay);

View file

@ -31,7 +31,7 @@ var bluePanel = mainPanel.addChild(new FloatingUIPanel ({
offsetPosition: { x: 0.1, y: 0.1, z: 0.2 }
}));
var mainPanelBackground = new BillboardOverlay({
var mainPanelBackground = new Image3DOverlay({
url: BG_IMAGE_URL,
dimensions: {
x: 0.5,
@ -84,7 +84,7 @@ var text = mainPanel.addChild(new Text3DOverlay({
backgroundAlpha: 0.9
}));
var redDot = mainPanel.addChild(new BillboardOverlay({
var redDot = mainPanel.addChild(new Image3DOverlay({
url: RED_DOT_IMAGE_URL,
dimensions: {
x: 0.1,
@ -100,7 +100,7 @@ var redDot = mainPanel.addChild(new BillboardOverlay({
}
}));
var redDot2 = mainPanel.addChild(new BillboardOverlay({
var redDot2 = mainPanel.addChild(new Image3DOverlay({
url: RED_DOT_IMAGE_URL,
dimensions: {
x: 0.1,
@ -116,7 +116,7 @@ var redDot2 = mainPanel.addChild(new BillboardOverlay({
}
}));
var blueSquare = bluePanel.addChild(new BillboardOverlay({
var blueSquare = bluePanel.addChild(new Image3DOverlay({
url: BLUE_SQUARE_IMAGE_URL,
dimensions: {
x: 0.1,
@ -132,7 +132,7 @@ var blueSquare = bluePanel.addChild(new BillboardOverlay({
}
}));
var blueSquare2 = bluePanel.addChild(new BillboardOverlay({
var blueSquare2 = bluePanel.addChild(new Image3DOverlay({
url: BLUE_SQUARE_IMAGE_URL,
dimensions: {
x: 0.1,

View file

@ -340,7 +340,7 @@ SelectionDisplay = (function () {
leftMargin: 0,
});
var grabberMoveUp = Overlays.addOverlay("billboard", {
var grabberMoveUp = Overlays.addOverlay("image3d", {
url: HIFI_PUBLIC_BUCKET + "images/up-arrow.svg",
position: { x:0, y: 0, z: 0},
color: handleColor,
@ -609,7 +609,7 @@ SelectionDisplay = (function () {
minorTickMarksColor: { red: 0, green: 0, blue: 0 },
});
var yawHandle = Overlays.addOverlay("billboard", {
var yawHandle = Overlays.addOverlay("image3d", {
url: ROTATE_ARROW_WEST_NORTH_URL,
position: { x:0, y: 0, z: 0},
color: handleColor,
@ -622,7 +622,7 @@ SelectionDisplay = (function () {
});
var pitchHandle = Overlays.addOverlay("billboard", {
var pitchHandle = Overlays.addOverlay("image3d", {
url: ROTATE_ARROW_WEST_NORTH_URL,
position: { x:0, y: 0, z: 0},
color: handleColor,
@ -635,7 +635,7 @@ SelectionDisplay = (function () {
});
var rollHandle = Overlays.addOverlay("billboard", {
var rollHandle = Overlays.addOverlay("image3d", {
url: ROTATE_ARROW_WEST_NORTH_URL,
position: { x:0, y: 0, z: 0},
color: handleColor,

View file

@ -61,7 +61,7 @@ LightOverlayManager = function() {
// Allocate or get an unused overlay
function getOverlay() {
if (unusedOverlays.length == 0) {
var overlay = Overlays.addOverlay("billboard", {
var overlay = Overlays.addOverlay("image3d", {
});
allOverlays.push(overlay);
} else {

View file

@ -8,7 +8,7 @@
// Manage overlays with object oriented goodness, instead of ugly `Overlays.h` methods.
// Instead of:
//
// var billboard = Overlays.addOverlay("billboard", { visible: false });
// var billboard = Overlays.addOverlay("image3d", { visible: false });
// ...
// Overlays.editOverlay(billboard, { visible: true });
// ...
@ -16,7 +16,7 @@
//
// You can now do:
//
// var billboard = new BillboardOverlay({ visible: false });
// var billboard = new Image3DOverlay({ visible: false });
// ...
// billboard.visible = true;
// ...
@ -41,8 +41,13 @@
var overlays = {};
var panels = {};
var overlayTypes;
var Overlay, Overlay2D, Base3DOverlay, Planar3DOverlay, Volume3DOverlay;
var overlayTypes,
Overlay,
Overlay2D,
Base3DOverlay,
Planar3DOverlay,
Billboard3DOverlay,
Volume3DOverlay;
//
@ -123,7 +128,7 @@
//
// Usage:
// // Create an overlay
// var billboard = new BillboardOverlay({
// var billboard = new Image3DOverlay({
// visible: true,
// isFacingAvatar: true,
// ignoreRayIntersections: false
@ -234,6 +239,10 @@
Overlays.deleteOverlay(this._id);
};
that.prototype.isPanelAttachable = function() {
return true;
};
return generateOverlayClass(that, ABSTRACT, [
"alpha", "glowLevel", "pulseMax", "pulseMin", "pulsePeriod", "glowLevelPulse",
"alphaPulse", "colorPulse", "visible", "anchor"
@ -253,6 +262,11 @@
"dimensions"
]);
Billboard3DOverlay = generateOverlayClass(Planar3DOverlay, ABSTRACT, [
"isFacingAvatar"
].concat(PANEL_ATTACHABLE_FIELDS));
Billboard3DOverlay.prototype.isPanelAttachable = function() { return true; };
Volume3DOverlay = generateOverlayClass(Base3DOverlay, ABSTRACT, [
"dimensions"
]);
@ -261,14 +275,18 @@
"subImage", "imageURL"
]);
generateOverlayClass(Billboard3DOverlay, "image3d", [
"url", "subImage"
]);
generateOverlayClass(Overlay2D, "text", [
"font", "text", "backgroundColor", "backgroundAlpha", "leftMargin", "topMargin"
]);
generateOverlayClass(Planar3DOverlay, "text3d", [
generateOverlayClass(Billboard3DOverlay, "text3d", [
"text", "backgroundColor", "backgroundAlpha", "lineHeight", "leftMargin", "topMargin",
"rightMargin", "bottomMargin", "isFacingAvatar"
].concat(PANEL_ATTACHABLE_FIELDS));
"rightMargin", "bottomMargin"
]);
generateOverlayClass(Volume3DOverlay, "cube", [
"borderSize"
@ -300,13 +318,10 @@
generateOverlayClass(Volume3DOverlay, "model", [
"url", "dimensions", "textures"
]);
generateOverlayClass(Planar3DOverlay, "billboard", [
"url", "subImage", "isFacingAvatar"
].concat(PANEL_ATTACHABLE_FIELDS));
})();
ImageOverlay = overlayTypes["image"];
Image3DOverlay = overlayTypes["image3d"];
TextOverlay = overlayTypes["text"];
Text3DOverlay = overlayTypes["text3d"];
Cube3DOverlay = overlayTypes["cube"];
@ -317,7 +332,6 @@
Grid3DOverlay = overlayTypes["grid"];
LocalModelsOverlay = overlayTypes["localmodels"];
ModelOverlay = overlayTypes["model"];
BillboardOverlay = overlayTypes["billboard"];
//
@ -334,6 +348,10 @@
that.prototype.constructor = that;
that.AddChildException = function(message) {
this.message = message;
};
var FIELDS = ["offsetPosition", "offsetRotation", "facingRotation"];
FIELDS.forEach(function(prop) {
Object.defineProperty(that.prototype, prop, {
@ -351,13 +369,6 @@
var PSEUDO_FIELDS = [];
PSEUDO_FIELDS.push("children");
Object.defineProperty(that.prototype, "children", {
get: function() {
return this._children.slice();
}
});
PSEUDO_FIELDS.push("visible");
Object.defineProperty(that.prototype, "visible", {
get: function() {
@ -371,8 +382,20 @@
}
});
Object.defineProperty(that.prototype, "attachedPanel", {
get: function() {
return this._attachedPanelPointer;
}
});
Object.defineProperty(that.prototype, "children", {
get: function() {
return this._children.slice();
}
});
that.prototype.addChild = function(child) {
if (child instanceof Overlay) {
if (child instanceof Overlay && child.isPanelAttachable()) {
Overlays.setAttachedPanel(child._id, this._id);
} else if (child instanceof FloatingUIPanel) {
child.setProperties({
@ -385,6 +408,8 @@
value: this._id
}
});
} else {
throw new that.AddChildException("Given child is not panel attachable.");
}
child._attachedPanelPointer = this;
child.visible = this.visible;
@ -431,8 +456,8 @@
function onOverlayDeleted(id) {
if (id in overlays) {
if (overlays[id]._attachedPanelPointer) {
overlays[id]._attachedPanelPointer.removeChild(overlays[id]);
if (overlays[id].attachedPanel) {
overlays[id].attachedPanel.removeChild(overlays[id]);
}
delete overlays[id];
}
@ -440,9 +465,14 @@
function onPanelDeleted(id) {
if (id in panels) {
// Overlays will automatically delete all child overlays, but not all child panels. We
// have to do that ourselves.
panels[id]._children.forEach(function(child) {
child.destroy();
});
if (panels[id].attachedPanel) {
panels[id].attachedPanel.removeChild(panels[id]);
}
delete panels[id];
}
}

View file

@ -148,7 +148,7 @@ KeyboardKey = (function(keyboard, keyProperties) {
};
for (var i = 0; i < this.bounds.length; i++) {
if (THREE_D_MODE) {
this.overlays.push(Overlays.addOverlay("billboard", {
this.overlays.push(Overlays.addOverlay("image3d", {
scale: 1,
rotation: MyAvatar.rotation,
isFacingAvatar: false,
@ -202,7 +202,7 @@ Keyboard = (function(params) {
return windowDimensions.y - this.height();
};
if (THREE_D_MODE) {
this.background = Overlays.addOverlay("billboard", {
this.background = Overlays.addOverlay("image3d", {
scale: 1,
position: MyAvatar.position,
rotation: MyAvatar.rotation,

View file

@ -260,7 +260,7 @@ function notify(notice, button, height) {
positions = calculate3DOverlayPositions(noticeWidth, noticeHeight, notice.y);
notifications.push((Overlays.addOverlay("text3d", notice)));
buttons.push((Overlays.addOverlay("billboard", button)));
buttons.push((Overlays.addOverlay("image3d", button)));
overlay3DDetails.push({
notificationOrientation: positions.notificationOrientation,
notificationPosition: positions.notificationPosition,

View file

@ -117,7 +117,7 @@
visible: false,
ignoreRayIntersection: true
});
bar3D.overlay = Overlays.addOverlay("billboard", {
bar3D.overlay = Overlays.addOverlay("image3d", {
url: BAR_URL,
subImage: { x: BAR_WIDTH, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT },
scale: SCALE_3D * BAR_WIDTH,

View file

@ -175,7 +175,7 @@ function SeatIndicator(modelProperties, seatIndex) {
modelProperties.sittingPoints[seatIndex].rotation);
this.scale = MyAvatar.scale / 12;
this.sphere = Overlays.addOverlay("billboard", {
this.sphere = Overlays.addOverlay("image3d", {
subImage: { x: 0, y: buttonHeight, width: buttonWidth, height: buttonHeight},
url: buttonImageUrl,
position: this.position,

View file

@ -0,0 +1,55 @@
//
// Billboard3DOverlay.cpp
// hifi/interface/src/ui/overlays
//
// Created by Zander Otavka on 8/4/15.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Billboard3DOverlay.h"
#include "Application.h"
Billboard3DOverlay::Billboard3DOverlay() :
_isFacingAvatar(false)
{
}
Billboard3DOverlay::Billboard3DOverlay(const Billboard3DOverlay* billboard3DOverlay) :
Planar3DOverlay(billboard3DOverlay),
PanelAttachable(billboard3DOverlay),
_isFacingAvatar(billboard3DOverlay->_isFacingAvatar)
{
}
void Billboard3DOverlay::setProperties(const QScriptValue &properties) {
Planar3DOverlay::setProperties(properties);
PanelAttachable::setProperties(properties);
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
if (isFacingAvatarValue.isValid()) {
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
}
}
QScriptValue Billboard3DOverlay::getProperty(const QString &property) {
if (property == "isFacingAvatar") {
return _isFacingAvatar;
}
QScriptValue value = PanelAttachable::getProperty(_scriptEngine, property);
if (value.isValid()) {
return value;
}
return Planar3DOverlay::getProperty(property);
}
void Billboard3DOverlay::setTransforms(Transform& transform) {
PanelAttachable::setTransforms(transform);
if (_isFacingAvatar) {
glm::quat rotation = Application::getInstance()->getCamera()->getOrientation();
transform.setRotation(rotation);
}
}

View file

@ -0,0 +1,38 @@
//
// Billboard3DOverlay.h
// hifi/interface/src/ui/overlays
//
// Created by Zander Otavka on 8/4/15.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Billboard3DOverlay_h
#define hifi_Billboard3DOverlay_h
#include "Planar3DOverlay.h"
#include "PanelAttachable.h"
class Billboard3DOverlay : public Planar3DOverlay, public PanelAttachable {
Q_OBJECT
public:
Billboard3DOverlay();
Billboard3DOverlay(const Billboard3DOverlay* billboard3DOverlay);
bool getIsFacingAvatar() const { return _isFacingAvatar; }
void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; }
virtual void setProperties(const QScriptValue& properties);
virtual QScriptValue getProperty(const QString& property);
protected:
virtual void setTransforms(Transform& transform);
private:
bool _isFacingAvatar;
};
#endif // hifi_Billboard3DOverlay_h

View file

@ -1,15 +1,16 @@
//
// BillboardOverlay.cpp
// Image3DOverlay.cpp
//
//
// Created by Clement on 7/1/14.
// Modified and renamed by Zander Otavka on 8/4/15
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "BillboardOverlay.h"
#include "Image3DOverlay.h"
#include <QScriptValue>
@ -17,41 +18,30 @@
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <gpu/Batch.h>
#include <GLMHelpers.h>
#include "Application.h"
#include "GeometryUtil.h"
QString const BillboardOverlay::TYPE = "billboard";
QString const Image3DOverlay::TYPE = "image3d";
BillboardOverlay::BillboardOverlay() {
Image3DOverlay::Image3DOverlay() {
_isLoaded = false;
}
BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) :
Planar3DOverlay(billboardOverlay),
PanelAttachable(billboardOverlay),
_url(billboardOverlay->_url),
_texture(billboardOverlay->_texture),
_fromImage(billboardOverlay->_fromImage),
_isFacingAvatar(billboardOverlay->_isFacingAvatar)
Image3DOverlay::Image3DOverlay(const Image3DOverlay* image3DOverlay) :
Billboard3DOverlay(image3DOverlay),
_url(image3DOverlay->_url),
_texture(image3DOverlay->_texture),
_fromImage(image3DOverlay->_fromImage)
{
}
void BillboardOverlay::setTransforms(Transform& transform) {
PanelAttachable::setTransforms(transform);
if (_isFacingAvatar) {
glm::quat rotation = Application::getInstance()->getCamera()->getOrientation();
transform.setRotation(rotation);
}
}
void BillboardOverlay::update(float deltatime) {
void Image3DOverlay::update(float deltatime) {
setTransforms(_transform);
}
void BillboardOverlay::render(RenderArgs* args) {
void Image3DOverlay::render(RenderArgs* args) {
if (!_texture) {
_isLoaded = true;
_texture = DependencyManager::get<TextureCache>()->getTexture(_url);
@ -104,7 +94,7 @@ void BillboardOverlay::render(RenderArgs* args) {
batch->setModelTransform(transform);
batch->setResourceTexture(0, _texture->getGPUTexture());
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(*batch, true, true, false, true);
DependencyManager::get<GeometryCache>()->renderQuad(
*batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
@ -114,15 +104,14 @@ void BillboardOverlay::render(RenderArgs* args) {
batch->setResourceTexture(0, args->_whiteTexture); // restore default white color after me
}
void BillboardOverlay::setProperties(const QScriptValue &properties) {
Planar3DOverlay::setProperties(properties);
PanelAttachable::setProperties(properties);
void Image3DOverlay::setProperties(const QScriptValue &properties) {
Billboard3DOverlay::setProperties(properties);
QScriptValue urlValue = properties.property("url");
if (urlValue.isValid()) {
QString newURL = urlValue.toVariant().toString();
if (newURL != _url) {
setBillboardURL(newURL);
setURL(newURL);
}
}
@ -156,50 +145,34 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) {
setClipFromSource(subImageRect);
}
}
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
if (isFacingAvatarValue.isValid()) {
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
}
}
QScriptValue BillboardOverlay::getProperty(const QString& property) {
QScriptValue Image3DOverlay::getProperty(const QString& property) {
if (property == "url") {
return _url;
}
if (property == "subImage") {
return qRectToScriptValue(_scriptEngine, _fromImage);
}
if (property == "isFacingAvatar") {
return _isFacingAvatar;
}
if (property == "offsetPosition") {
return vec3toScriptValue(_scriptEngine, getOffsetPosition());
}
QScriptValue value = PanelAttachable::getProperty(_scriptEngine, property);
if (value.isValid()) {
return value;
}
return Planar3DOverlay::getProperty(property);
return Billboard3DOverlay::getProperty(property);
}
void BillboardOverlay::setURL(const QString& url) {
setBillboardURL(url);
}
void BillboardOverlay::setBillboardURL(const QString& url) {
void Image3DOverlay::setURL(const QString& url) {
_url = url;
_isLoaded = false;
}
bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face) {
bool Image3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face) {
if (_texture && _texture->isLoaded()) {
// Make sure position and rotation is updated.
setTransforms(_transform);
// Produce the dimensions of the billboard based on the image's aspect ratio and the overlay's scale.
// Produce the dimensions of the overlay based on the image's aspect ratio and the overlay's scale.
bool isNull = _fromImage.isNull();
float width = isNull ? _texture->getWidth() : _fromImage.width();
float height = isNull ? _texture->getHeight() : _fromImage.height();
@ -212,6 +185,6 @@ bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::v
return false;
}
BillboardOverlay* BillboardOverlay::createClone() const {
return new BillboardOverlay(this);
Image3DOverlay* Image3DOverlay::createClone() const {
return new Image3DOverlay(this);
}

View file

@ -1,30 +1,31 @@
//
// BillboardOverlay.h
// Image3DOverlay.h
//
//
// Created by Clement on 7/1/14.
// Modified and renamed by Zander Otavka on 8/4/15
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_BillboardOverlay_h
#define hifi_BillboardOverlay_h
#ifndef hifi_Image3DOverlay_h
#define hifi_Image3DOverlay_h
#include <TextureCache.h>
#include "Planar3DOverlay.h"
#include "PanelAttachable.h"
#include "Billboard3DOverlay.h"
class BillboardOverlay : public Planar3DOverlay, public PanelAttachable {
class Image3DOverlay : public Billboard3DOverlay {
Q_OBJECT
public:
static QString const TYPE;
virtual QString getType() const { return TYPE; }
BillboardOverlay();
BillboardOverlay(const BillboardOverlay* billboardOverlay);
Image3DOverlay();
Image3DOverlay(const Image3DOverlay* image3DOverlay);
virtual void render(RenderArgs* args);
@ -32,28 +33,20 @@ public:
// setters
void setURL(const QString& url);
void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; }
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
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);
virtual BillboardOverlay* createClone() const;
protected:
virtual void setTransforms(Transform& transform);
virtual Image3DOverlay* createClone() const;
private:
void setBillboardURL(const QString& url);
QString _url;
NetworkTexturePointer _texture;
QRect _fromImage; // where from in the image to sample
bool _isFacingAvatar = true;
QRect _fromImage; // where from in the image to sample
};
#endif // hifi_BillboardOverlay_h
#endif // hifi_Image3DOverlay_h

View file

@ -19,7 +19,7 @@
#include <RegisteredMetaTypes.h>
#include "Application.h"
#include "BillboardOverlay.h"
#include "Image3DOverlay.h"
#include "Circle3DOverlay.h"
#include "Cube3DOverlay.h"
#include "ImageOverlay.h"
@ -160,8 +160,8 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope
thisOverlay = std::make_shared<LocalModelsOverlay>(Application::getInstance()->getEntityClipboardRenderer());
} else if (type == ModelOverlay::TYPE) {
thisOverlay = std::make_shared<ModelOverlay>();
} else if (type == BillboardOverlay::TYPE) {
thisOverlay = std::make_shared<BillboardOverlay>();
} else if (type == Image3DOverlay::TYPE) {
thisOverlay = std::make_shared<Image3DOverlay>();
}
if (thisOverlay) {

View file

@ -18,7 +18,7 @@
#include <LODManager.h>
#include <render/Scene.h>
#include "BillboardOverlay.h"
#include "Image3DOverlay.h"
#include "Circle3DOverlay.h"
#include "Cube3DOverlay.h"
#include "ImageOverlay.h"

View file

@ -32,15 +32,13 @@ Text3DOverlay::Text3DOverlay() :
_leftMargin(DEFAULT_MARGIN),
_topMargin(DEFAULT_MARGIN),
_rightMargin(DEFAULT_MARGIN),
_bottomMargin(DEFAULT_MARGIN),
_isFacingAvatar(false)
_bottomMargin(DEFAULT_MARGIN)
{
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
}
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
Planar3DOverlay(text3DOverlay),
PanelAttachable(text3DOverlay),
Billboard3DOverlay(text3DOverlay),
_text(text3DOverlay->_text),
_backgroundColor(text3DOverlay->_backgroundColor),
_backgroundAlpha(text3DOverlay->_backgroundAlpha),
@ -48,8 +46,7 @@ Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
_leftMargin(text3DOverlay->_leftMargin),
_topMargin(text3DOverlay->_topMargin),
_rightMargin(text3DOverlay->_rightMargin),
_bottomMargin(text3DOverlay->_bottomMargin),
_isFacingAvatar(text3DOverlay->_isFacingAvatar)
_bottomMargin(text3DOverlay->_bottomMargin)
{
_textRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE);
}
@ -77,14 +74,6 @@ xColor Text3DOverlay::getBackgroundColor() {
return result;
}
void Text3DOverlay::setTransforms(Transform &transform) {
PanelAttachable::setTransforms(transform);
if (_isFacingAvatar) {
glm::quat rotation = Application::getInstance()->getCamera()->getOrientation();
transform.setRotation(rotation);
}
}
void Text3DOverlay::update(float deltatime) {
setTransforms(_transform);
}
@ -136,8 +125,7 @@ void Text3DOverlay::render(RenderArgs* args) {
}
void Text3DOverlay::setProperties(const QScriptValue& properties) {
Planar3DOverlay::setProperties(properties);
PanelAttachable::setProperties(properties);
Billboard3DOverlay::setProperties(properties);
QScriptValue text = properties.property("text");
if (text.isValid()) {
@ -179,12 +167,6 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
if (properties.property("bottomMargin").isValid()) {
setBottomMargin(properties.property("bottomMargin").toVariant().toFloat());
}
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
if (isFacingAvatarValue.isValid()) {
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
}
}
QScriptValue Text3DOverlay::getProperty(const QString& property) {
@ -212,15 +194,8 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
if (property == "bottomMargin") {
return _bottomMargin;
}
if (property == "isFacingAvatar") {
return _isFacingAvatar;
}
QScriptValue value = PanelAttachable::getProperty(_scriptEngine, property);
if (value.isValid()) {
return value;
}
return Planar3DOverlay::getProperty(property);
return Billboard3DOverlay::getProperty(property);
}
Text3DOverlay* Text3DOverlay::createClone() const {
@ -238,5 +213,5 @@ QSizeF Text3DOverlay::textSize(const QString& text) const {
bool Text3DOverlay::findRayIntersection(const glm::vec3 &origin, const glm::vec3 &direction, float &distance, BoxFace &face) {
setTransforms(_transform);
return Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
return Billboard3DOverlay::findRayIntersection(origin, direction, distance, face);
}

View file

@ -13,12 +13,11 @@
#include <QString>
#include "Planar3DOverlay.h"
#include "PanelAttachable.h"
#include "Billboard3DOverlay.h"
class TextRenderer3D;
class Text3DOverlay : public Planar3DOverlay, public PanelAttachable {
class Text3DOverlay : public Billboard3DOverlay {
Q_OBJECT
public:
@ -39,7 +38,6 @@ public:
float getTopMargin() const { return _topMargin; }
float getRightMargin() const { return _rightMargin; }
float getBottomMargin() const { return _bottomMargin; }
bool getIsFacingAvatar() const { return _isFacingAvatar; }
xColor getBackgroundColor();
float getBackgroundAlpha() const { return _backgroundAlpha; }
@ -50,7 +48,6 @@ public:
void setTopMargin(float margin) { _topMargin = margin; }
void setRightMargin(float margin) { _rightMargin = margin; }
void setBottomMargin(float margin) { _bottomMargin = margin; }
void setIsFacingAvatar(bool isFacingAvatar) { _isFacingAvatar = isFacingAvatar; }
virtual void setProperties(const QScriptValue& properties);
virtual QScriptValue getProperty(const QString& property);
@ -61,9 +58,6 @@ public:
virtual Text3DOverlay* createClone() const;
protected:
virtual void setTransforms(Transform& transform);
private:
TextRenderer3D* _textRenderer = nullptr;
@ -75,7 +69,6 @@ private:
float _topMargin;
float _rightMargin;
float _bottomMargin;
bool _isFacingAvatar;
};