#include <simgear/props/condition.hxx>
#include <simgear/props/props.hxx>
+#include <simgear/scene/material/Effect.hxx>
+#include <simgear/scene/material/EffectGeode.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;
namespace {
/**
virtual void apply(osg::Geode& node)
{
- maybeGetMaterialValues(node.getStateSet());
+ using namespace simgear;
+ EffectGeode* eg = dynamic_cast<EffectGeode*>(&node);
+ if (eg) {
+ const Effect* effect = eg->getEffect();
+ if (effect)
+ for (vector<osg::ref_ptr<Technique> >::const_iterator itr
+ = effect->techniques.begin(), end = effect->techniques.end();
+ itr != end;
+ ++itr) {
+ const Technique* tniq = itr->get();
+ for (vector<osg::ref_ptr<Pass> >::const_iterator pitr
+ = tniq->passes.begin(), pend = tniq->passes.end();
+ pitr != pend;
+ ++pitr)
+ maybeGetMaterialValues(pitr->get());
+ }
+ } else {
+ maybeGetMaterialValues(node.getStateSet());
+ }
int numDrawables = node.getNumDrawables();
for (int i = 0; i < numDrawables; i++) {
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i));
}
}
- void maybeGetMaterialValues(osg::StateSet* stateSet)
+ void maybeGetMaterialValues(const osg::StateSet* stateSet)
{
if (!stateSet)
return;
- osg::Material* nodeMat
- = dynamic_cast<osg::Material*>(stateSet->getAttribute(osg::StateAttribute::MATERIAL));
+ const osg::Material* nodeMat
+ = dynamic_cast<const osg::Material*>(stateSet
+ ->getAttribute(osg::StateAttribute
+ ::MATERIAL));
if (!nodeMat)
return;
material = nodeMat;
}
- osg::ref_ptr<osg::Material> material;
+ osg::ref_ptr<const osg::Material> material;
osg::Vec4 ambientDiffuse;
};
class UpdateCallback : public osg::NodeCallback {
public:
UpdateCallback(const osgDB::FilePathList& texturePathList,
- const SGCondition* condition,
const SGPropertyNode* configNode, SGPropertyNode* modelRoot) :
- _condition(condition),
_materialProps(configNode, modelRoot),
_texturePathList(texturePathList),
_prevState(false)
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osg::StateSet* stateSet = node->getStateSet();
- if ((!_condition || _condition->test()) && stateSet) {
+ if (stateSet) {
if (_textureProp) {
std::string textureName = _textureProp->getStringValue();
if (_textureName != textureName) {
traverse(node, nv);
}
private:
- SGSharedPtr<const SGCondition> _condition;
SGSharedPtr<const SGPropertyNode> _textureProp;
SGSharedPtr<const SGPropertyNode> _thresholdProp;
std::string _textureName;
mat->setDataVariance(osg::Object::DYNAMIC);
unsigned defaultColorModeMask = 0;
mat->setUpdateCallback(0); // Just to make sure.
+ // XXX This should probably go away, as ac3d models always have a
+ // DIFFUSE color mode.
switch (mat->getColorMode()) {
case osg::Material::OFF:
defaultColorModeMask = 0;
|| getConfig()->hasChild("threshold-prop") || getCondition()) {
stateSet->setDataVariance(osg::Object::DYNAMIC);
group->setUpdateCallback(new UpdateCallback(texturePathList,
- getCondition(),
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;
+ }
}
void
}
defaultAmbientDiffuse = defaultsVisitor.ambientDiffuse;
}
+
+const char* colorNames[] =
+{
+ "ambient",
+ "diffuse",
+ "specular",
+ "emission"
+};
+
+// Build an effect which mimics the material color mode in a
+// shader. The OpenGL material values will be overridden by the
+// material animation's material.
+//
+// This is a hack to get the effect to respect the values set in the
+// material, set up by the animation, which overrides the values in
+// the effect's material attributes. Things will be different when
+// material animations are implemented purely by manipulating effects.
+
+SGPropertyNode_ptr
+SGMaterialAnimation::makeEffectProperties(const SGPropertyNode* animProp)
+{
+ SGPropertyNode_ptr eRoot = new SGPropertyNode;
+ SGPropertyNode* inherit = makeNode(eRoot, "inherits-from");
+ if (animProp->hasChild("diffuse") || animProp->hasChild("transparency"))
+ inherit->setStringValue("Effects/material-off");
+ else
+ inherit->setStringValue("Effects/material-diffuse");
+ return eRoot;
+}