-SGMaterialAnimation::SGMaterialAnimation( SGPropertyNode *prop_root,
- SGPropertyNode_ptr props, const SGPath &texture_path)
- : SGAnimation(props, new osg::Group),
- _last_condition(false),
- _prop_root(prop_root),
- _prop_base(""),
- _texture_base(texture_path),
- _read(0),
- _update(0),
- _global(props->getBoolValue("global", false))
-{
- SGPropertyNode_ptr n;
- n = props->getChild("condition");
- _condition = n ? sgReadCondition(_prop_root, n) : 0;
- n = props->getChild("property-base");
- if (n) {
- _prop_base = n->getStringValue();
- if (!_prop_base.empty() && _prop_base.end()[-1] != '/')
- _prop_base += '/';
- }
-
- initColorGroup(props->getChild("diffuse"), &_diff, DIFFUSE);
- initColorGroup(props->getChild("ambient"), &_amb, AMBIENT);
- initColorGroup(props->getChild("emission"), &_emis, EMISSION);
- initColorGroup(props->getChild("specular"), &_spec, SPECULAR);
-
- _shi = props->getFloatValue("shininess", -1.0);
- if (_shi >= 0.0)
- _update |= SHININESS;
-
- SGPropertyNode_ptr group = props->getChild("transparency");
- if (group) {
- _trans.value = group->getFloatValue("alpha", -1.0);
- _trans.factor = group->getFloatValue("factor", 1.0);
- _trans.offset = group->getFloatValue("offset", 0.0);
- _trans.min = group->getFloatValue("min", 0.0);
- if (_trans.min < 0.0)
- _trans.min = 0.0;
- _trans.max = group->getFloatValue("max", 1.0);
- if (_trans.max > 1.0)
- _trans.max = 1.0;
- if (_trans.dirty())
- _update |= TRANSPARENCY;
-
- n = group->getChild("alpha-prop");
- _trans.value_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("factor-prop");
- _trans.factor_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("offset-prop");
- _trans.offset_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- if (_trans.live())
- _read |= TRANSPARENCY;
- }
-
- _thresh = props->getFloatValue("threshold", -1.0);
- if (_thresh >= 0.0)
- _update |= THRESHOLD;
-
- string _texture_str = props->getStringValue("texture", "");
- if (!_texture_str.empty()) {
- _texture = _texture_base;
- _texture.append(_texture_str);
- _update |= TEXTURE;
- }
-
- n = props->getChild("shininess-prop");
- _shi_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = props->getChild("threshold-prop");
- _thresh_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = props->getChild("texture-prop");
- _tex_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
-
- _static_update = _update;
-
- _alphaFunc = new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0);
- _texture2D = SGLoadTexture2D(_texture);
-}
-
-void SGMaterialAnimation::initColorGroup(SGPropertyNode_ptr group, ColorSpec *col, int flag)
-{
- if (!group)
- return;
-
- col->red = group->getFloatValue("red", -1.0);
- col->green = group->getFloatValue("green", -1.0);
- col->blue = group->getFloatValue("blue", -1.0);
- col->factor = group->getFloatValue("factor", 1.0);
- col->offset = group->getFloatValue("offset", 0.0);
- if (col->dirty())
- _update |= flag;
-
- SGPropertyNode *n;
- n = group->getChild("red-prop");
- col->red_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("green-prop");
- col->green_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("blue-prop");
- col->blue_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("factor-prop");
- col->factor_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- n = group->getChild("offset-prop");
- col->offset_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
- if (col->live())
- _read |= flag;
-}
-
-void SGMaterialAnimation::init()
-{
- if (!_global)
- cloneMaterials(_branch);
-
- // OSGFIXME
- osg::StateSet* stateSet = _branch->getOrCreateStateSet();
- if (_update & THRESHOLD) {
- stateSet->setAttribute(_alphaFunc.get(), osg::StateAttribute::OVERRIDE);
- stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
- }
- if (_update & TEXTURE) {
- stateSet->setTextureAttribute(0, _texture2D.get(), osg::StateAttribute::OVERRIDE);
- stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
- }