mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
LP-29 improve initialization of scene graph
addresses issue with initial camera position
This commit is contained in:
parent
6c6f184d28
commit
a59740a5ff
@ -165,20 +165,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool attach(osgViewer::View *view)
|
||||
{
|
||||
attachCamera(view->getCamera());
|
||||
attachManipulator(view);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool detach(osgViewer::View *view)
|
||||
{
|
||||
detachManipulator(view);
|
||||
detachCamera(view->getCamera());
|
||||
return true;
|
||||
}
|
||||
|
||||
void attachCamera(osg::Camera *camera)
|
||||
{
|
||||
qDebug() << "OSGCamera::attach" << camera;
|
||||
@ -269,8 +255,7 @@ public:
|
||||
qDebug() << "OSGCamera::attachManipulator - use NodeTrackerManipulator";
|
||||
if (trackNode && trackNode->node()) {
|
||||
// setup tracking camera
|
||||
// TODO when camera is thrown, then changing attitude has jitter (could be due to different frequency between refresh and animation)
|
||||
// TODO who takes ownership?
|
||||
// TODO when camera is thrown, then changing attitude has jitter
|
||||
osgGA::NodeTrackerManipulator *ntm = new osgGA::NodeTrackerManipulator(
|
||||
/*osgGA::StandardManipulator::COMPUTE_HOME_USING_BBOX | osgGA::StandardManipulator::DEFAULT_SETTINGS*/);
|
||||
switch (trackerMode) {
|
||||
@ -608,14 +593,16 @@ void OSGCamera::setLogarithmicDepthBuffer(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
bool OSGCamera::attach(osgViewer::View *view)
|
||||
void OSGCamera::attach(osgViewer::View *view)
|
||||
{
|
||||
return h->attach(view);
|
||||
h->attachCamera(view->getCamera());
|
||||
h->attachManipulator(view);
|
||||
}
|
||||
|
||||
bool OSGCamera::detach(osgViewer::View *view)
|
||||
void OSGCamera::detach(osgViewer::View *view)
|
||||
{
|
||||
return h->detach(view);
|
||||
h->detachCamera(view->getCamera());
|
||||
h->detachManipulator(view);
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
||||
|
@ -117,8 +117,8 @@ public:
|
||||
bool logarithmicDepthBuffer();
|
||||
void setLogarithmicDepthBuffer(bool enabled);
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void fieldOfViewChanged(qreal arg);
|
||||
|
@ -145,6 +145,28 @@ QQmlListProperty<OSGNode> OSGGroup::children()
|
||||
&Hidden::at_child,
|
||||
&Hidden::clear_child);
|
||||
}
|
||||
|
||||
void OSGGroup::attach(osgViewer::View *view)
|
||||
{
|
||||
// qDebug() << "OSGGroup::attach " << view;
|
||||
QListIterator<OSGNode *> i(h->children);
|
||||
while (i.hasNext()) {
|
||||
OSGNode *node = i.next();
|
||||
// qDebug() << "OSGGroup::attach - child" << node;
|
||||
node->attach(view);
|
||||
}
|
||||
}
|
||||
|
||||
void OSGGroup::detach(osgViewer::View *view)
|
||||
{
|
||||
// qDebug() << "OSGGroup::detach " << view;
|
||||
QListIterator<OSGNode *> i(h->children);
|
||||
while (i.hasNext()) {
|
||||
OSGNode *node = i.next();
|
||||
// qDebug() << "OSGGroup::detach - child" << node;
|
||||
node->detach(view);
|
||||
}
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
||||
#include "OSGGroup.moc"
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
|
||||
QQmlListProperty<OSGNode> children();
|
||||
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
private:
|
||||
struct Hidden;
|
||||
Hidden *h;
|
||||
|
@ -123,12 +123,6 @@ public:
|
||||
}
|
||||
modelNode->addUpdateCallback(nodeUpdateCallback.get());
|
||||
|
||||
// get "size" of model
|
||||
osg::ComputeBoundsVisitor cbv;
|
||||
modelNode->accept(cbv);
|
||||
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
||||
offset = bbox.radius();
|
||||
|
||||
self->setNode(modelNode);
|
||||
|
||||
dirty = true;
|
||||
@ -136,17 +130,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool attach(osgViewer::View *view)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool detach(osgViewer::View *view)
|
||||
{
|
||||
qWarning() << "OSGModelNode::detach - not implemented";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool acceptSceneData(OSGNode *node)
|
||||
{
|
||||
qDebug() << "OSGModelNode::acceptSceneData" << node;
|
||||
@ -183,6 +166,14 @@ public:
|
||||
if (clampToTerrain) {
|
||||
osgEarth::MapNode *mapNode = osgEarth::MapNode::findMapNode(sceneData->node());
|
||||
if (mapNode) {
|
||||
// get "size" of model
|
||||
// TODO this should be done once only...
|
||||
osg::ComputeBoundsVisitor cbv;
|
||||
modelNode->accept(cbv);
|
||||
const osg::BoundingBox & bbox = cbv.getBoundingBox();
|
||||
offset = bbox.radius();
|
||||
|
||||
// clamp model to terrain if needed
|
||||
intoTerrain = clampGeoPoint(geoPoint, offset, mapNode);
|
||||
} else {
|
||||
qWarning() << "OSGModelNode::updateNode - scene data does not contain a map node";
|
||||
@ -355,14 +346,21 @@ void OSGModelNode::setPosition(QVector3D arg)
|
||||
}
|
||||
}
|
||||
|
||||
bool OSGModelNode::attach(osgViewer::View *view)
|
||||
void OSGModelNode::attach(osgViewer::View *view)
|
||||
{
|
||||
return h->attach(view);
|
||||
// qDebug() << "OSGModelNode::attach " << view;
|
||||
if (h->modelData) {
|
||||
h->modelData->attach(view);
|
||||
}
|
||||
h->updateNode();
|
||||
}
|
||||
|
||||
bool OSGModelNode::detach(osgViewer::View *view)
|
||||
void OSGModelNode::detach(osgViewer::View *view)
|
||||
{
|
||||
return h->detach(view);
|
||||
// qDebug() << "OSGModelNode::detach " << view;
|
||||
if (h->modelData) {
|
||||
h->modelData->detach(view);
|
||||
}
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
||||
|
@ -72,8 +72,8 @@ public:
|
||||
QVector3D position() const;
|
||||
void setPosition(QVector3D arg);
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void modelDataChanged(OSGNode *node);
|
||||
|
@ -57,27 +57,11 @@ void OSGNode::setNode(osg::Node *node)
|
||||
}
|
||||
}
|
||||
|
||||
bool OSGNode::attach(osgViewer::View *view)
|
||||
void OSGNode::attach(osgViewer::View *view)
|
||||
{
|
||||
QListIterator<QObject *> i(children());
|
||||
while (i.hasNext()) {
|
||||
OSGNode *node = qobject_cast<OSGNode *>(i.next());
|
||||
if (node) {
|
||||
node->attach(view);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OSGNode::detach(osgViewer::View *view)
|
||||
void OSGNode::detach(osgViewer::View *view)
|
||||
{
|
||||
QListIterator<QObject *> i(children());
|
||||
while (i.hasNext()) {
|
||||
OSGNode *node = qobject_cast<OSGNode *>(i.next());
|
||||
if (node) {
|
||||
node->detach(view);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
@ -41,6 +41,7 @@ class View;
|
||||
} // namespace osgViewer
|
||||
|
||||
namespace osgQtQuick {
|
||||
|
||||
class OSGQTQUICK_EXPORT OSGNode : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
@ -51,8 +52,8 @@ public:
|
||||
osg::Node *node() const;
|
||||
void setNode(osg::Node *node);
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void nodeChanged(osg::Node *node) const;
|
||||
|
@ -183,20 +183,18 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool attach(osgViewer::View *view)
|
||||
void attachSkyNode(osgViewer::View *view)
|
||||
{
|
||||
if (!skyNode.valid()) {
|
||||
qWarning() << "OSGSkyNode::attach - invalid sky node" << skyNode;
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
skyNode->attach(view, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool detach(osgViewer::View *view)
|
||||
void detachSkyNode(osgViewer::View *view)
|
||||
{
|
||||
qWarning() << "OSGSkyNode::detach - not implemented";
|
||||
return true;
|
||||
// TODO find a way to detach the skyNode (?)
|
||||
}
|
||||
|
||||
OSGSkyNode *const self;
|
||||
@ -275,14 +273,22 @@ void OSGSkyNode::setMinimumAmbientLight(double arg)
|
||||
}
|
||||
}
|
||||
|
||||
bool OSGSkyNode::attach(osgViewer::View *view)
|
||||
void OSGSkyNode::attach(osgViewer::View *view)
|
||||
{
|
||||
return h->attach(view);
|
||||
// qDebug() << "OSGSkyNode::attach " << view;
|
||||
if (h->sceneData) {
|
||||
h->sceneData->attach(view);
|
||||
}
|
||||
h->attachSkyNode(view);
|
||||
}
|
||||
|
||||
bool OSGSkyNode::detach(osgViewer::View *view)
|
||||
void OSGSkyNode::detach(osgViewer::View *view)
|
||||
{
|
||||
return h->detach(view);
|
||||
// qDebug() << "OSGSkyNode::detach " << view;
|
||||
h->detachSkyNode(view);
|
||||
if (h->sceneData) {
|
||||
h->sceneData->detach(view);
|
||||
}
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
||||
|
@ -66,8 +66,8 @@ public:
|
||||
double minimumAmbientLight();
|
||||
void setMinimumAmbientLight(double arg);
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void sceneDataChanged(OSGNode *node);
|
||||
|
@ -85,17 +85,12 @@ public:
|
||||
}
|
||||
|
||||
osg::Transform *transform = getOrCreateTransform();
|
||||
if (!transform) {
|
||||
qWarning() << "OSGTransformNode::acceptNode - transform is null";
|
||||
return false;
|
||||
}
|
||||
|
||||
transform->addChild(node);
|
||||
|
||||
self->setNode(transform);
|
||||
|
||||
dirty = true;
|
||||
updateNode();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -232,6 +227,23 @@ void OSGTransformNode::setPosition(QVector3D arg)
|
||||
emit positionChanged(position());
|
||||
}
|
||||
}
|
||||
|
||||
void OSGTransformNode::attach(osgViewer::View *view)
|
||||
{
|
||||
// qDebug() << "OSGTransformNode::attach " << view;
|
||||
if (h->modelData) {
|
||||
h->modelData->attach(view);
|
||||
}
|
||||
h->updateNode();
|
||||
}
|
||||
|
||||
void OSGTransformNode::detach(osgViewer::View *view)
|
||||
{
|
||||
// qDebug() << "OSGTransformNode::detach " << view;
|
||||
if (h->modelData) {
|
||||
h->modelData->detach(view);
|
||||
}
|
||||
}
|
||||
} // namespace osgQtQuick
|
||||
|
||||
#include "OSGTransformNode.moc"
|
||||
|
@ -60,6 +60,9 @@ public:
|
||||
QVector3D position() const;
|
||||
void setPosition(QVector3D arg);
|
||||
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void modelDataChanged(OSGNode *node);
|
||||
|
||||
|
@ -152,37 +152,32 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool attach(osgViewer::View *view)
|
||||
void attach(osgViewer::View *view)
|
||||
{
|
||||
if (!sceneData) {
|
||||
qWarning() << "OSGViewport::attach - invalid scene!";
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// attach scene
|
||||
if (!attach(view, sceneData->node())) {
|
||||
qWarning() << "OSGViewport::attach - failed to attach node!";
|
||||
return false;
|
||||
}
|
||||
attach(view, sceneData->node());
|
||||
// attach camera
|
||||
if (camera) {
|
||||
camera->attach(view);
|
||||
} else {
|
||||
qWarning() << "OSGViewport::attach - no camera!";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool attach(osgViewer::View *view, osg::Node *node)
|
||||
void attach(osgViewer::View *view, osg::Node *node)
|
||||
{
|
||||
qDebug() << "OSGViewport::attach" << node;
|
||||
if (!view) {
|
||||
qWarning() << "OSGViewport::attach - view is null";
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (!node) {
|
||||
qWarning() << "OSGViewport::attach - node is null";
|
||||
view->setSceneData(NULL);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_OSGEARTH
|
||||
@ -199,17 +194,16 @@ public:
|
||||
|
||||
qDebug() << "OSGViewport::attach - set scene" << node;
|
||||
view->setSceneData(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool detach(osgViewer::View *view)
|
||||
void detach(osgViewer::View *view)
|
||||
{
|
||||
qDebug() << "OSGViewport::detach" << view;
|
||||
// detach camera
|
||||
if (camera) {
|
||||
camera->detach(view);
|
||||
}
|
||||
return true;
|
||||
// detach scene
|
||||
view->setSceneData(NULL);
|
||||
}
|
||||
|
||||
void onSceneGraphInitialized()
|
||||
@ -543,6 +537,7 @@ public:
|
||||
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
|
||||
{
|
||||
QOpenGLFramebufferObjectFormat format;
|
||||
|
||||
format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
// format.setSamples(4);
|
||||
|
||||
@ -640,41 +635,22 @@ QQuickFramebufferObject::Renderer *OSGViewport::createRenderer() const
|
||||
return new ViewportRenderer(h);
|
||||
}
|
||||
|
||||
bool OSGViewport::attach(osgViewer::View *view)
|
||||
void OSGViewport::attach(osgViewer::View *view)
|
||||
{
|
||||
qDebug() << "OSGViewport::attach" << view;
|
||||
|
||||
h->attach(view);
|
||||
|
||||
QListIterator<QObject *> i(children());
|
||||
while (i.hasNext()) {
|
||||
QObject *object = i.next();
|
||||
OSGNode *node = qobject_cast<OSGNode *>(object);
|
||||
if (node) {
|
||||
qDebug() << "OSGViewport::attach - child" << node;
|
||||
node->attach(view);
|
||||
}
|
||||
// qDebug() << "OSGViewport::attach" << view;
|
||||
if (h->sceneData) {
|
||||
h->sceneData->attach(view);
|
||||
}
|
||||
|
||||
return true;
|
||||
h->attach(view);
|
||||
}
|
||||
|
||||
bool OSGViewport::detach(osgViewer::View *view)
|
||||
void OSGViewport::detach(osgViewer::View *view)
|
||||
{
|
||||
qDebug() << "OSGViewport::detach" << view;
|
||||
|
||||
QListIterator<QObject *> i(children());
|
||||
while (i.hasNext()) {
|
||||
QObject *object = i.next();
|
||||
OSGNode *node = qobject_cast<OSGNode *>(object);
|
||||
if (node) {
|
||||
node->detach(view);
|
||||
}
|
||||
}
|
||||
|
||||
h->detach(view);
|
||||
|
||||
return true;
|
||||
if (h->sceneData) {
|
||||
h->sceneData->detach(view);
|
||||
}
|
||||
}
|
||||
|
||||
void OSGViewport::releaseResources()
|
||||
|
@ -75,8 +75,8 @@ public:
|
||||
virtual Renderer *createRenderer() const;
|
||||
virtual void releaseResources();
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
virtual void attach(osgViewer::View *view);
|
||||
virtual void detach(osgViewer::View *view);
|
||||
|
||||
signals:
|
||||
void updateModeChanged(UpdateMode::Enum mode);
|
||||
|
@ -61,9 +61,9 @@ OSGViewport {
|
||||
|
||||
OSGTransformNode {
|
||||
id: modelTransformNode
|
||||
modelData: modelFileNode
|
||||
// model dimensions are in mm, scale to meters
|
||||
scale: Qt.vector3d(0.001, 0.001, 0.001)
|
||||
modelData: modelFileNode
|
||||
}
|
||||
|
||||
OSGFileNode {
|
||||
|
Loading…
x
Reference in New Issue
Block a user