The evaluation of the condition is moved to a ConditionNode and
separated from the animation of values via properties. Previously the
conditional application of static values was broken.
#include <simgear/scene/material/Pass.hxx>
#include <simgear/scene/material/Technique.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/scene/material/Pass.hxx>
#include <simgear/scene/material/Technique.hxx>
#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/ConditionNode.hxx>
using namespace std;
using namespace simgear;
using namespace std;
using namespace simgear;
class UpdateCallback : public osg::NodeCallback {
public:
UpdateCallback(const osgDB::FilePathList& texturePathList,
class UpdateCallback : public osg::NodeCallback {
public:
UpdateCallback(const osgDB::FilePathList& texturePathList,
- const SGCondition* condition,
const SGPropertyNode* configNode, SGPropertyNode* modelRoot) :
const SGPropertyNode* configNode, SGPropertyNode* modelRoot) :
_materialProps(configNode, modelRoot),
_texturePathList(texturePathList),
_prevState(false)
_materialProps(configNode, modelRoot),
_texturePathList(texturePathList),
_prevState(false)
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osg::StateSet* stateSet = node->getStateSet();
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osg::StateSet* stateSet = node->getStateSet();
- if ((!_condition || _condition->test()) && stateSet) {
if (_textureProp) {
std::string textureName = _textureProp->getStringValue();
if (_textureName != textureName) {
if (_textureProp) {
std::string textureName = _textureProp->getStringValue();
if (_textureName != textureName) {
traverse(node, nv);
}
private:
traverse(node, nv);
}
private:
- SGSharedPtr<const SGCondition> _condition;
SGSharedPtr<const SGPropertyNode> _textureProp;
SGSharedPtr<const SGPropertyNode> _thresholdProp;
std::string _textureName;
SGSharedPtr<const SGPropertyNode> _textureProp;
SGSharedPtr<const SGPropertyNode> _thresholdProp;
std::string _textureName;
|| getConfig()->hasChild("threshold-prop") || getCondition()) {
stateSet->setDataVariance(osg::Object::DYNAMIC);
group->setUpdateCallback(new UpdateCallback(texturePathList,
|| getConfig()->hasChild("threshold-prop") || getCondition()) {
stateSet->setDataVariance(osg::Object::DYNAMIC);
group->setUpdateCallback(new UpdateCallback(texturePathList,
getConfig(), inputRoot));
} else {
stateSet->setDataVariance(osg::Object::STATIC);
}
getConfig(), inputRoot));
} else {
stateSet->setDataVariance(osg::Object::STATIC);
}
- parent.addChild(group);
- return group;
+ if (getCondition()) {
+ ConditionNode* cn = new ConditionNode;
+ cn->setCondition(getCondition());
+ osg::Group* modelGroup = new osg::Group;
+ group->addChild(modelGroup);
+ cn->addChild(group);
+ cn->addChild(modelGroup);
+ parent.addChild(cn);
+ return modelGroup;
+ } else {
+ parent.addChild(group);
+ return group;
+ }