diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp similarity index 51% rename from ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.cpp rename to ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp index cb015aa01..90d1e46a1 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.cpp @@ -1,7 +1,7 @@ /** ****************************************************************************** * - * @file OSGBackgroundNode.cpp + * @file OSGBillboardNode.cpp * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. * @addtogroup * @{ @@ -25,95 +25,69 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "OSGBackgroundNode.hpp" +#include "OSGBillboardNode.hpp" #include #include +#include + #include -#include #include namespace osgQtQuick { -enum DirtyFlag { URL = 1 << 0 }; +enum DirtyFlag {}; -struct OSGBackgroundNode::Hidden : public QObject { +struct OSGBillboardNode::Hidden : public QObject { Q_OBJECT private: - OSGBackgroundNode * const self; + OSGBillboardNode * const self; + + osg::ref_ptr camera; public: - QUrl url; - - Hidden(OSGBackgroundNode *self) : QObject(self), self(self), url() + Hidden(OSGBillboardNode *self) : QObject(self), self(self) {} - void updateURL() + osg::Node *createNode() { - qDebug() << "OSGBackgroundNode::updateNode - reading image file" << url.path(); - osg::ref_ptr texture = new osg::Texture2D; - - osg::ref_ptr quad = osg::createTexturedQuadGeometry( - osg::Vec3(), osg::Vec3(1.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 1.0f, 0.0f)); - quad->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture.get()); - - osg::ref_ptr geode = new osg::Geode; - geode->addDrawable(quad.get()); - - osg::Camera *camera = new osg::Camera; + camera = new osg::Camera; camera->setClearMask(0); camera->setCullingActive(false); camera->setAllowEventFocus(false); camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setRenderOrder(osg::Camera::POST_RENDER); camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0)); - camera->addChild(geode.get()); osg::StateSet *ss = camera->getOrCreateStateSet(); ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); ss->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 1.0, 1.0)); - self->setNode(camera); - - osg::ref_ptr image = osgDB::readImageFile(url.path().toStdString()); - texture->setImage(image.get()); + return camera; } }; -/* class OSGBackgroundNode */ +/* class OSGBillboardNode */ -OSGBackgroundNode::OSGBackgroundNode(QObject *parent) : Inherited(parent), h(new Hidden(this)) +OSGBillboardNode::OSGBillboardNode(QObject *parent) : Inherited(parent), h(new Hidden(this)) {} -OSGBackgroundNode::~OSGBackgroundNode() +OSGBillboardNode::~OSGBillboardNode() { - qDebug() << "OSGBackgroundNode::~OSGBackgroundNode"; + qDebug() << "OSGBillboardNode::~OSGBillboardNode"; delete h; } -const QUrl OSGBackgroundNode::imageFile() const +osg::Node *OSGBillboardNode::createNode() { - return h->url; + return h->createNode(); } -void OSGBackgroundNode::setImageFile(const QUrl &url) +void OSGBillboardNode::updateNode() { - if (h->url != url) { - h->url = url; - setDirty(URL); - emit imageFileChanged(url); - } -} - -void OSGBackgroundNode::update() -{ - Inherited::update(); - - if (isDirty(URL)) { - h->updateURL(); - } + Inherited::updateNode(); } } // namespace osgQtQuick -#include "OSGBackgroundNode.moc" +#include "OSGBillboardNode.moc" diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.hpp new file mode 100644 index 000000000..e12b604d0 --- /dev/null +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBillboardNode.hpp @@ -0,0 +1,54 @@ +/** + ****************************************************************************** + * + * @file OSGBillboardNode.hpp + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * @addtogroup + * @{ + * @addtogroup + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _H_OSGQTQUICK_BILLBOARDNODE_H_ +#define _H_OSGQTQUICK_BILLBOARDNODE_H_ + +#include "Export.hpp" +#include "OSGGroup.hpp" + +namespace osgQtQuick { +class OSGQTQUICK_EXPORT OSGBillboardNode : public OSGGroup { + Q_OBJECT + + typedef OSGGroup Inherited; + +public: + OSGBillboardNode(QObject *parent = 0); + virtual ~OSGBillboardNode(); + +protected: + virtual osg::Node *createNode(); + virtual void updateNode(); + +private: + struct Hidden; + Hidden *const h; +}; +} // namespace osgQtQuick + +#endif // _H_OSGQTQUICK_BILLBOARDNODE_H_ diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.cpp index 36102ee99..277e7439f 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.cpp @@ -66,16 +66,6 @@ public: public: Hidden(OSGCamera *self) : QObject(self), self(self), fieldOfView(90), clearColor(0, 0, 0, 255), logDepthBufferEnabled(false) { - // default blue osg::Vec4f(0.2f, 0.99f, 0.4f, 1.0f) - camera = new osg::Camera(); - - camera->setClearColor(osg::Vec4(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF())); - - osg::StateSet *stateset = camera->getOrCreateStateSet(); - stateset->setGlobalDefaults(); - - self->setNode(camera); - #ifdef USE_OSGEARTH logDepthBuffer = NULL; #endif @@ -92,6 +82,18 @@ public: #endif } + osg::Node *createNode() + { + camera = new osg::Camera(); + + camera->setClearColor(osg::Vec4(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF())); + + osg::StateSet *stateset = camera->getOrCreateStateSet(); + stateset->setGlobalDefaults(); + + return camera; + } + void updateClearColor() { if (!camera.valid()) { @@ -239,20 +241,14 @@ void OSGCamera::setLogarithmicDepthBuffer(bool enabled) } } -osg::Camera *OSGCamera::asCamera() const +osg::Node *OSGCamera::createNode() { - // BAD introduce templating - return (osg::Camera *)node(); + return h->createNode(); } -void OSGCamera::setGraphicsContext(osg::GraphicsContext *gc) +void OSGCamera::updateNode() { - h->setGraphicsContext(gc); -} - -void OSGCamera::update() -{ - Inherited::update(); + Inherited::updateNode(); if (isDirty(ClearColor)) { h->updateClearColor(); @@ -264,6 +260,17 @@ void OSGCamera::update() h->updateLogDepthBuffer(); } } + +osg::Camera *OSGCamera::asCamera() const +{ + // BAD introduce templating + return (osg::Camera *)node(); +} + +void OSGCamera::setGraphicsContext(osg::GraphicsContext *gc) +{ + h->setGraphicsContext(gc); +} } // namespace osgQtQuick #include "OSGCamera.moc" diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.hpp index e32ca49fe..869ddc87b 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGCamera.hpp @@ -68,7 +68,8 @@ signals: void logarithmicDepthBufferChanged(bool enabled); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.cpp index 518dd87b1..fe8fb8ab5 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.cpp @@ -88,7 +88,7 @@ public: Hidden(OSGFileNode *self) : QObject(self), self(self), source(), async(false), optimizeMode(OptimizeMode::None) {} - void updateNode() + void updateSource() { qDebug() << "OSGFileNode::updateNode" << source; if (!source.isValid()) { @@ -197,9 +197,15 @@ void OSGFileNode::setOptimizeMode(OptimizeMode::Enum optimizeMode) } } -void OSGFileNode::update() +osg::Node *OSGFileNode::createNode() { - Inherited::update(); + // node is created later + return NULL; +} + +void OSGFileNode::updateNode() +{ + Inherited::updateNode(); if (isDirty(Async)) { // do nothing... @@ -208,7 +214,7 @@ void OSGFileNode::update() // TODO: trigger a node update ? } if (isDirty(Source)) { - h->updateNode(); + h->updateSource(); } } } // namespace osgQtQuick diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.hpp index 645a4a1ec..97f050202 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGFileNode.hpp @@ -71,7 +71,8 @@ signals: void optimizeModeChanged(OptimizeMode::Enum); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp index d9a590c13..50f5a6683 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.cpp @@ -60,10 +60,13 @@ public: QVector3D position; Hidden(OSGGeoTransformNode *self) : QObject(self), self(self), childNode(NULL), sceneNode(NULL), offset(-1.0), clampToTerrain(false), intoTerrain(false) + {} + + osg::Node *createNode() { transform = new osgEarth::GeoTransform(); transform->setAutoRecomputeHeights(true); - self->setNode(transform); + return transform; } bool acceptChildNode(OSGNode *node) @@ -268,9 +271,14 @@ void OSGGeoTransformNode::setPosition(QVector3D arg) } } -void OSGGeoTransformNode::update() +osg::Node *OSGGeoTransformNode::createNode() { - Inherited::update(); + return h->createNode(); +} + +void OSGGeoTransformNode::updateNode() +{ + Inherited::updateNode(); if (isDirty(Child)) { h->updateChildNode(); diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp index 7d25f6ea4..788d6cd1e 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGeoTransformNode.hpp @@ -36,8 +36,7 @@ // TODO derive from OSGGroup... namespace osgQtQuick { class OSGQTQUICK_EXPORT OSGGeoTransformNode : public OSGNode { - Q_OBJECT - Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) + Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) Q_PROPERTY(osgQtQuick::OSGNode * sceneNode READ sceneNode WRITE setSceneNode NOTIFY sceneNodeChanged) Q_PROPERTY(bool clampToTerrain READ clampToTerrain WRITE setClampToTerrain NOTIFY clampToTerrainChanged) Q_PROPERTY(bool intoTerrain READ intoTerrain NOTIFY intoTerrainChanged) @@ -74,7 +73,8 @@ signals: void positionChanged(QVector3D arg); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.cpp index c757876d8..84b1fecfe 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.cpp @@ -41,17 +41,17 @@ struct OSGGroup::Hidden : public QObject { private: OSGGroup * const self; - osg::ref_ptr group; - QMap cache; -public: QList children; +public: Hidden(OSGGroup *self) : QObject(self), self(self) + {} + + osg::Node *createNode() { - group = new osg::Group(); - self->setNode(group); + return new osg::Group(); } void appendChild(OSGNode *childNode) @@ -86,9 +86,16 @@ public: self->setDirty(Children); } - void updateGroupNode() + void updateChildren() { - qDebug() << "OSGGeoTransformNode::updateGroupNode"; + qDebug() << "OSGGroup::updateChildren"; + + osg::Group *group = static_cast(self->node()); + if (!group) { + qWarning() << "OSGGroup::updateChildren - null group"; + return; + } + bool updated = false; unsigned int index = 0; @@ -145,6 +152,13 @@ private slots: void onChildNodeChanged(osg::Node *node) { qDebug() << "OSGGroup::onChildNodeChanged" << node; + + osg::Group *group = static_cast(self->node()); + if (!group) { + qWarning() << "OSGGroup::onChildNodeChanged - null group"; + return; + } + OSGNode *obj = qobject_cast(sender()); if (obj) { osg::Node *cacheNode = cache.value(obj, NULL); @@ -179,12 +193,17 @@ QQmlListProperty OSGGroup::children() const &Hidden::clear_child); } -void OSGGroup::update() +osg::Node *OSGGroup::createNode() { - Inherited::update(); + return h->createNode(); +} + +void OSGGroup::updateNode() +{ + Inherited::updateNode(); if (isDirty(Children)) { - h->updateGroupNode(); + h->updateChildren(); } } } // namespace osgQtQuick diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.hpp index 6487e076f..b57f2ed3e 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGGroup.hpp @@ -48,7 +48,8 @@ public: QQmlListProperty children() const; protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.cpp new file mode 100644 index 000000000..4699f4052 --- /dev/null +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.cpp @@ -0,0 +1,129 @@ +/** + ****************************************************************************** + * + * @file OSGImageNode.cpp + * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. + * @addtogroup + * @{ + * @addtogroup + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "OSGImageNode.hpp" + +#include + +#include + +#include +#include + +namespace osgQtQuick { +enum DirtyFlag { ImageFile = 1 << 0 }; + +struct OSGImageNode::Hidden : public QObject { + Q_OBJECT + +private: + OSGImageNode * const self; + + osg::ref_ptr texture; + +public: + QUrl url; + + Hidden(OSGImageNode *self) : QObject(self), self(self), url() + {} + + osg::Node *createNode() + { + osg::Drawable *quad = osg::createTexturedQuadGeometry(osg::Vec3(0, 0, 0), osg::Vec3(1, 0, 0), osg::Vec3(0, 1, 0)); + + osg::Geode *geode = new osg::Geode; + + geode->addDrawable(quad); + + geode->setStateSet(createState()); + + return geode; + } + + osg::StateSet *createState() + { + texture = new osg::Texture2D; + + // create the StateSet to store the texture data + osg::StateSet *stateset = new osg::StateSet; + + stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); + + return stateset; + } + + void updateImageFile() + { + qDebug() << "OSGImageNode::updateImageFile - reading image file" << url.path(); + osg::Image *image = osgDB::readImageFile(url.path().toStdString()); + if (texture.valid()) { + texture->setImage(image); + } + } +}; + +/* class OSGImageNode */ + +OSGImageNode::OSGImageNode(QObject *parent) : Inherited(parent), h(new Hidden(this)) +{} + +OSGImageNode::~OSGImageNode() +{ + qDebug() << "OSGImageNode::~OSGImageNode"; + delete h; +} + +const QUrl OSGImageNode::imageFile() const +{ + return h->url; +} + +void OSGImageNode::setImageFile(const QUrl &url) +{ + if (h->url != url) { + h->url = url; + setDirty(ImageFile); + emit imageFileChanged(url); + } +} + +osg::Node *OSGImageNode::createNode() +{ + return h->createNode(); +} + +void OSGImageNode::updateNode() +{ + Inherited::updateNode(); + + if (isDirty(ImageFile)) { + h->updateImageFile(); + } +} +} // namespace osgQtQuick + +#include "OSGImageNode.moc" diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.hpp similarity index 79% rename from ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.hpp rename to ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.hpp index 191530996..0b1d4ff12 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGBackgroundNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGImageNode.hpp @@ -1,7 +1,7 @@ /** ****************************************************************************** * - * @file OSGBackgroundNode.hpp + * @file OSGImageNode.hpp * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015. * @addtogroup * @{ @@ -25,26 +25,23 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _H_OSGQTQUICK_BACKGROUNDNODE_H_ -#define _H_OSGQTQUICK_BACKGROUNDNODE_H_ +#ifndef _H_OSGQTQUICK_IMAGENODE_H_ +#define _H_OSGQTQUICK_IMAGENODE_H_ #include "Export.hpp" #include "OSGNode.hpp" #include -QT_BEGIN_NAMESPACE -class QUrl; -QT_END_NAMESPACE namespace osgQtQuick { -class OSGQTQUICK_EXPORT OSGBackgroundNode : public OSGNode { +class OSGQTQUICK_EXPORT OSGImageNode : public OSGNode { Q_OBJECT Q_PROPERTY(QUrl imageFile READ imageFile WRITE setImageFile NOTIFY imageFileChanged) typedef OSGNode Inherited; public: - OSGBackgroundNode(QObject *parent = 0); - virtual ~OSGBackgroundNode(); + OSGImageNode(QObject *parent = 0); + virtual ~OSGImageNode(); const QUrl imageFile() const; void setImageFile(const QUrl &url); @@ -53,7 +50,8 @@ signals: void imageFileChanged(const QUrl &url); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; @@ -61,4 +59,4 @@ private: }; } // namespace osgQtQuick -#endif // _H_OSGQTQUICK_BACKGROUNDNODE_H_ +#endif // _H_OSGQTQUICK_IMAGENODE_H_ diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.cpp index c8db2a789..ce7032499 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.cpp @@ -59,7 +59,7 @@ public: void update() { - return self->update(); + return self->updateNode(); } bool acceptNode(osg::Node *aNode) @@ -119,21 +119,13 @@ void OSGNode::clearDirty() h->clearDirty(); } -void OSGNode::classBegin() +osg::Node *OSGNode::createNode() { - // qDebug() << "OSGNode::classBegin" << this; + return NULL; } -void OSGNode::componentComplete() -{ - qDebug() << "OSGNode::componentComplete" << this; - update(); - clearDirty(); - h->complete = true; - if (!h->node.valid()) { - qWarning() << "OSGNode::componentComplete - node is not valid!" << this; - } -} +void OSGNode::updateNode() +{} void OSGNode::emitNodeChanged() { @@ -142,8 +134,25 @@ void OSGNode::emitNodeChanged() } } -void OSGNode::update() -{} +void OSGNode::classBegin() +{ + qDebug() << "OSGNode::classBegin" << this; + + setNode(createNode()); +} + +void OSGNode::componentComplete() +{ + qDebug() << "OSGNode::componentComplete" << this; + + updateNode(); + clearDirty(); + h->complete = true; + if (!h->node.valid()) { + qWarning() << "OSGNode::componentComplete - node is not valid!" << this; + } + qDebug() << "OSGNode::componentComplete DONE" << this; +} } // namespace osgQtQuick #include "OSGNode.moc" diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.hpp index 97c62888f..fb4e506af 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGNode.hpp @@ -69,12 +69,13 @@ protected: void setDirty(int mask = 0xFFFF); void clearDirty(); - void classBegin(); - void componentComplete(); + virtual osg::Node *createNode(); + virtual void updateNode(); void emitNodeChanged(); - virtual void update(); + void classBegin(); + void componentComplete(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.cpp index 294c80882..829cf0966 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.cpp @@ -37,7 +37,7 @@ #include namespace osgQtQuick { -enum DirtyFlag { Type = 1 << 0 }; +enum DirtyFlag { ShapeType = 1 << 0 }; struct OSGShapeNode::Hidden : public QObject { Q_OBJECT @@ -51,7 +51,7 @@ public: Hidden(OSGShapeNode *self) : QObject(self), self(self), shapeType(ShapeType::Sphere) {} - void updateNode() + void updateShapeType() { osg::Node *node = NULL; @@ -69,18 +69,15 @@ public: node = ShapeUtils::create3DAxis(); break; } - // Add the node to the scene self->setNode(node); } }; /* class OSGShapeNode */ -// TODO turn into generic shape node... -// see http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/TransformsAndStates OSGShapeNode::OSGShapeNode(QObject *parent) : Inherited(parent), h(new Hidden(this)) { - setDirty(Type); + setDirty(ShapeType); } OSGShapeNode::~OSGShapeNode() @@ -98,17 +95,22 @@ void OSGShapeNode::setShapeType(ShapeType::Enum type) { if (h->shapeType != type) { h->shapeType = type; - setDirty(Type); + setDirty(ShapeType); emit shapeTypeChanged(type); } } -void OSGShapeNode::update() +osg::Node *OSGShapeNode::createNode() { - Inherited::update(); + return NULL; +} - if (isDirty(Type)) { - h->updateNode(); +void OSGShapeNode::updateNode() +{ + Inherited::updateNode(); + + if (isDirty(ShapeType)) { + h->updateShapeType(); } } } // namespace osgQtQuick diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.hpp index 6095476e7..452334379 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGShapeNode.hpp @@ -55,7 +55,8 @@ signals: void shapeTypeChanged(ShapeType::Enum); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.cpp index 8eff4c2e2..0754ed17a 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.cpp @@ -303,9 +303,14 @@ void OSGSkyNode::setMinimumAmbientLight(double ambient) } } -void OSGSkyNode::update() +osg::Node *OSGSkyNode::createNode() { - Inherited::update(); + return NULL; +} + +void OSGSkyNode::updateNode() +{ + Inherited::updateNode(); if (isDirty(Scene)) { h->updateSkyNode(); diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.hpp index f6b1c01a9..3728b9dbc 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGSkyNode.hpp @@ -82,7 +82,8 @@ signals: void minimumAmbientLightChanged(double arg); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.cpp index ded1d61a3..d4aefccdb 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.cpp @@ -52,23 +52,23 @@ public: QColor color; Hidden(OSGTextNode *self) : QObject(self), self(self) + {} + + osg::Node *createNode() { osg::ref_ptr textFont = createFont(QFont("Times")); - text = createText(osg::Vec3(-100, 20, 0), "Hello World", 20.0f, - textFont.get()); - osg::ref_ptr textGeode = new osg::Geode(); + text = createText(osg::Vec3(-100, 20, 0), "Hello World", 20.0f, textFont.get()); + osg::ref_ptr textGeode = new osg::Geode(); textGeode->addDrawable(text.get()); #if 0 text->setAutoRotateToScreen(true); - self->setNode(textGeode.get()); #else osg::Camera *camera = createHUDCamera(-100, 100, -100, 100); camera->addChild(textGeode.get()); - camera->getOrCreateStateSet()->setMode( - GL_LIGHTING, osg::StateAttribute::OFF); - self->setNode(camera); + camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); #endif + return text; } void updateText() @@ -128,9 +128,14 @@ void OSGTextNode::setColor(const QColor &color) } } -void OSGTextNode::update() +osg::Node *OSGTextNode::createNode() { - Inherited::update(); + return h->createNode(); +} + +void OSGTextNode::updateNode() +{ + Inherited::updateNode(); if (isDirty(Text)) { h->updateText(); diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.hpp index 587a71901..8c84a6053 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTextNode.hpp @@ -55,7 +55,8 @@ signals: void colorChanged(const QColor &color); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp index 46f79ba18..8b958cd5f 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.cpp @@ -52,9 +52,12 @@ public: QVector3D position; Hidden(OSGTransformNode *self) : QObject(self), self(self), childNode(NULL) + {} + + osg::Node *createNode() { transform = new osg::PositionAttitudeTransform(); - self->setNode(transform); + return transform; } bool acceptChildNode(OSGNode *node) @@ -202,9 +205,14 @@ void OSGTransformNode::setPosition(QVector3D arg) } } -void OSGTransformNode::update() +osg::Node *OSGTransformNode::createNode() { - Inherited::update(); + return h->createNode(); +} + +void OSGTransformNode::updateNode() +{ + Inherited::updateNode(); if (isDirty(Child)) { h->updateChildNode(); diff --git a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp index 17f66965f..992b70c48 100644 --- a/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp +++ b/ground/gcs/src/libs/osgearth/osgQtQuick/OSGTransformNode.hpp @@ -36,8 +36,7 @@ // TODO derive from OSGGroup... namespace osgQtQuick { class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode { - Q_OBJECT - Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) + Q_OBJECT Q_PROPERTY(osgQtQuick::OSGNode *childNode READ childNode WRITE setChildNode NOTIFY childNodeChanged) Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged) Q_PROPERTY(QVector3D attitude READ attitude WRITE setAttitude NOTIFY attitudeChanged) Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) @@ -68,7 +67,8 @@ signals: void positionChanged(QVector3D arg); protected: - virtual void update(); + virtual osg::Node *createNode(); + virtual void updateNode(); private: struct Hidden; diff --git a/ground/gcs/src/libs/osgearth/osgearth.pro b/ground/gcs/src/libs/osgearth/osgearth.pro index 2a8205b8c..7b0fbd989 100644 --- a/ground/gcs/src/libs/osgearth/osgearth.pro +++ b/ground/gcs/src/libs/osgearth/osgearth.pro @@ -53,9 +53,10 @@ HEADERS += \ osgQtQuick/OSGGroup.hpp \ osgQtQuick/OSGTransformNode.hpp \ osgQtQuick/OSGShapeNode.hpp \ + osgQtQuick/OSGImageNode.hpp \ osgQtQuick/OSGTextNode.hpp \ osgQtQuick/OSGFileNode.hpp \ - osgQtQuick/OSGBackgroundNode.hpp \ + osgQtQuick/OSGBillboardNode.hpp \ osgQtQuick/OSGCamera.hpp \ osgQtQuick/OSGViewport.hpp @@ -65,9 +66,10 @@ SOURCES += \ osgQtQuick/OSGGroup.cpp \ osgQtQuick/OSGTransformNode.cpp \ osgQtQuick/OSGShapeNode.cpp \ + osgQtQuick/OSGImageNode.cpp \ osgQtQuick/OSGTextNode.cpp \ osgQtQuick/OSGFileNode.cpp \ - osgQtQuick/OSGBackgroundNode.cpp \ + osgQtQuick/OSGBillboardNode.cpp \ osgQtQuick/OSGCamera.cpp \ osgQtQuick/OSGViewport.cpp diff --git a/ground/gcs/src/libs/osgearth/utility.cpp b/ground/gcs/src/libs/osgearth/utility.cpp index 5551d40ee..5c4414e4c 100644 --- a/ground/gcs/src/libs/osgearth/utility.cpp +++ b/ground/gcs/src/libs/osgearth/utility.cpp @@ -33,8 +33,9 @@ #include "osgQtQuick/OSGFileNode.hpp" #include "osgQtQuick/OSGTransformNode.hpp" #include "osgQtQuick/OSGShapeNode.hpp" +#include "osgQtQuick/OSGImageNode.hpp" #include "osgQtQuick/OSGTextNode.hpp" -#include "osgQtQuick/OSGBackgroundNode.hpp" +#include "osgQtQuick/OSGBillboardNode.hpp" #include "osgQtQuick/OSGCamera.hpp" #include "osgQtQuick/OSGViewport.hpp" @@ -534,28 +535,34 @@ void registerTypes() { int maj = 1, min = 0; - // @uri osgQtQuick + // viewport + qmlRegisterType("OsgQtQuick", maj, min, "OSGViewport"); + qmlRegisterType("OsgQtQuick", maj, min, "UpdateMode"); + + // basic nodes qmlRegisterType("OsgQtQuick", maj, min, "OSGNode"); qmlRegisterType("OsgQtQuick", maj, min, "OSGGroup"); - qmlRegisterType("OsgQtQuick", maj, min, "OSGFileNode"); - qmlRegisterType("OsgQtQuick", maj, min, "OptimizeMode"); - qmlRegisterType("OsgQtQuick", maj, min, "OSGTransformNode"); - qmlRegisterType("OsgQtQuick", maj, min, "OSGTextNode"); - + // primitive nodes qmlRegisterType("OsgQtQuick", maj, min, "OSGShapeNode"); qmlRegisterType("OsgQtQuick", maj, min, "ShapeType"); - qmlRegisterType("OsgQtQuick", maj, min, "OSGBackgroundNode"); + qmlRegisterType("OsgQtQuick", maj, min, "OSGImageNode"); - qmlRegisterType("OsgQtQuick", maj, min, "OSGViewport"); - qmlRegisterType("OsgQtQuick", maj, min, "UpdateMode"); + qmlRegisterType("OsgQtQuick", maj, min, "OSGTextNode"); + qmlRegisterType("OsgQtQuick", maj, min, "OSGBillboardNode"); + + qmlRegisterType("OsgQtQuick", maj, min, "OSGFileNode"); + qmlRegisterType("OsgQtQuick", maj, min, "OptimizeMode"); + + // camera nodes qmlRegisterType("OsgQtQuick", maj, min, "OSGCamera"); + // camera manipulators qmlRegisterType("OsgQtQuick", maj, min, "OSGCameraManipulator"); qmlRegisterType("OsgQtQuick", maj, min, "OSGNodeTrackerManipulator"); qmlRegisterType("OsgQtQuick", maj, min, "TrackerMode"); diff --git a/ground/gcs/src/share/qml/model/ModelView.qml b/ground/gcs/src/share/qml/model/ModelView.qml index 200e3510c..8e7bea6f9 100644 --- a/ground/gcs/src/share/qml/model/ModelView.qml +++ b/ground/gcs/src/share/qml/model/ModelView.qml @@ -45,14 +45,16 @@ Item { OSGGroup { id: sceneNode - children: [ - transformNode, - backgroundNode - ] + children: [ transformNode, backgroundNode ] } - OSGBackgroundNode { + OSGBillboardNode { id: backgroundNode + children: [ backgroundImageNode ] + } + + OSGImageNode { + id: backgroundImageNode imageFile: pfdContext.backgroundImageFile }