mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
LP-29 fix dynamic scene changes handling
OSGTransform node was not properly handling child node changes
This commit is contained in:
parent
a93f182582
commit
72d4d6a79b
@ -49,72 +49,61 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Hidden(OSGTransformNode *parent) : QObject(parent), self(parent), modelData(NULL), dirty(false)
|
Hidden(OSGTransformNode *parent) : QObject(parent), self(parent), childNode(NULL), dirty(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~Hidden()
|
~Hidden()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool acceptModelData(OSGNode *node)
|
bool acceptChildNode(OSGNode *node)
|
||||||
{
|
{
|
||||||
qDebug() << "OSGTransformNode::acceptModelData" << node;
|
qDebug() << "OSGTransformNode::acceptChildNode" << node;
|
||||||
if (modelData == node) {
|
if (childNode == node) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modelData) {
|
if (childNode) {
|
||||||
disconnect(modelData);
|
disconnect(childNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
modelData = node;
|
childNode = node;
|
||||||
|
|
||||||
if (modelData) {
|
|
||||||
acceptNode(modelData->node());
|
|
||||||
connect(modelData, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onNodeChanged(osg::Node *)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool acceptNode(osg::Node *node)
|
|
||||||
{
|
|
||||||
qDebug() << "OSGTransformNode::acceptNode" << node;
|
|
||||||
if (!node) {
|
|
||||||
qWarning() << "OSGTransformNode::acceptNode - node is null";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Transform *transform = getOrCreateTransform();
|
|
||||||
|
|
||||||
transform->addChild(node);
|
|
||||||
|
|
||||||
self->setNode(transform);
|
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
|
||||||
return true;
|
if (childNode) {
|
||||||
}
|
connect(childNode, SIGNAL(nodeChanged(osg::Node *)), this, SLOT(onChildNodeChanged(osg::Node *)));
|
||||||
|
|
||||||
osg::Transform *getOrCreateTransform()
|
|
||||||
{
|
|
||||||
if (transform.valid()) {
|
|
||||||
return transform.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transform = new osg::PositionAttitudeTransform();
|
return true;
|
||||||
|
|
||||||
transform->addUpdateCallback(new NodeUpdateCallback(this));
|
|
||||||
|
|
||||||
return transform.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateNode()
|
void updateNode()
|
||||||
{
|
{
|
||||||
if (!dirty || !transform.valid()) {
|
if (!dirty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|
||||||
|
// qDebug() << "OSGTransformNode::updateNode" << this;
|
||||||
|
|
||||||
|
osg::PositionAttitudeTransform *transform = getOrCreateTransform();
|
||||||
|
|
||||||
|
if (transform->getNumChildren() == 0) {
|
||||||
|
if (childNode && childNode->node()) {
|
||||||
|
transform->addChild(childNode->node());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (childNode && childNode->node()) {
|
||||||
|
if (transform->getChild(0) != childNode->node()) {
|
||||||
|
transform->removeChild(0, 1);
|
||||||
|
transform->addChild(childNode->node());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
transform->removeChild(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
if ((scale.x() != 0.0) || (scale.y() != 0.0) || (scale.z() != 0.0)) {
|
if ((scale.x() != 0.0) || (scale.y() != 0.0) || (scale.z() != 0.0)) {
|
||||||
transform->setScale(osg::Vec3d(scale.x(), scale.y(), scale.z()));
|
transform->setScale(osg::Vec3d(scale.x(), scale.y(), scale.z()));
|
||||||
@ -136,24 +125,39 @@ public:
|
|||||||
transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z()));
|
transform->setPosition(osg::Vec3d(position.x(), position.y(), position.z()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osg::PositionAttitudeTransform *getOrCreateTransform()
|
||||||
|
{
|
||||||
|
if (transform.valid()) {
|
||||||
|
return transform.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
transform = new osg::PositionAttitudeTransform();
|
||||||
|
|
||||||
|
transform->addUpdateCallback(new NodeUpdateCallback(this));
|
||||||
|
|
||||||
|
self->setNode(transform);
|
||||||
|
|
||||||
|
return transform.get();
|
||||||
|
}
|
||||||
|
|
||||||
OSGTransformNode *const self;
|
OSGTransformNode *const self;
|
||||||
|
|
||||||
OSGNode *modelData;
|
OSGNode *childNode;
|
||||||
|
|
||||||
osg::ref_ptr<osg::PositionAttitudeTransform> transform;
|
osg::ref_ptr<osg::PositionAttitudeTransform> transform;
|
||||||
|
|
||||||
bool dirty;
|
|
||||||
|
|
||||||
QVector3D scale;
|
QVector3D scale;
|
||||||
QVector3D attitude;
|
QVector3D attitude;
|
||||||
QVector3D position;
|
QVector3D position;
|
||||||
|
|
||||||
|
bool dirty;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void onNodeChanged(osg::Node *node)
|
void onChildNodeChanged(osg::Node *node)
|
||||||
{
|
{
|
||||||
qDebug() << "OSGTransformNode::onNodeChanged" << node;
|
qDebug() << "OSGTransformNode::onChildNodeChanged" << node;
|
||||||
acceptNode(node);
|
dirty = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -161,6 +165,7 @@ private slots:
|
|||||||
|
|
||||||
void OSGTransformNode::Hidden::NodeUpdateCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
void OSGTransformNode::Hidden::NodeUpdateCallback::operator()(osg::Node *node, osg::NodeVisitor *nv)
|
||||||
{
|
{
|
||||||
|
nv->traverse(*node);
|
||||||
h->updateNode();
|
h->updateNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +181,12 @@ OSGTransformNode::~OSGTransformNode()
|
|||||||
|
|
||||||
OSGNode *OSGTransformNode::modelData()
|
OSGNode *OSGTransformNode::modelData()
|
||||||
{
|
{
|
||||||
return h->modelData;
|
return h->childNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSGTransformNode::setModelData(OSGNode *node)
|
void OSGTransformNode::setModelData(OSGNode *node)
|
||||||
{
|
{
|
||||||
if (h->acceptModelData(node)) {
|
if (h->acceptChildNode(node)) {
|
||||||
emit modelDataChanged(node);
|
emit modelDataChanged(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,8 +236,8 @@ void OSGTransformNode::setPosition(QVector3D arg)
|
|||||||
void OSGTransformNode::attach(osgViewer::View *view)
|
void OSGTransformNode::attach(osgViewer::View *view)
|
||||||
{
|
{
|
||||||
// qDebug() << "OSGTransformNode::attach " << view;
|
// qDebug() << "OSGTransformNode::attach " << view;
|
||||||
if (h->modelData) {
|
if (h->childNode) {
|
||||||
h->modelData->attach(view);
|
h->childNode->attach(view);
|
||||||
}
|
}
|
||||||
h->updateNode();
|
h->updateNode();
|
||||||
}
|
}
|
||||||
@ -240,8 +245,8 @@ void OSGTransformNode::attach(osgViewer::View *view)
|
|||||||
void OSGTransformNode::detach(osgViewer::View *view)
|
void OSGTransformNode::detach(osgViewer::View *view)
|
||||||
{
|
{
|
||||||
// qDebug() << "OSGTransformNode::detach " << view;
|
// qDebug() << "OSGTransformNode::detach " << view;
|
||||||
if (h->modelData) {
|
if (h->childNode) {
|
||||||
h->modelData->detach(view);
|
h->childNode->detach(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace osgQtQuick
|
} // namespace osgQtQuick
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
namespace osgQtQuick {
|
namespace osgQtQuick {
|
||||||
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode {
|
class OSGQTQUICK_EXPORT OSGTransformNode : public OSGNode {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// TODO rename to parentNode and modelNode
|
// TODO rename to childNode
|
||||||
Q_PROPERTY(osgQtQuick::OSGNode *modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
|
Q_PROPERTY(osgQtQuick::OSGNode *modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
|
Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
|
||||||
|
Loading…
Reference in New Issue
Block a user