Frederic Bouvier:
The attached patch adds a new animation class, called SGAlphaTestAnimation, to enable alpha test in 3D models. This will remove many artefact caused by painting order of translucent models, and I need it for an upcoming model. In addition, I added a min-factor and a max-factor to the range animation to modulate min-m, min-property, max-m or max-property.
This commit is contained in:
parent
7bee5f1ab6
commit
3d43bc0480
@ -217,23 +217,34 @@ SGNullAnimation::~SGNullAnimation ()
|
||||
SGRangeAnimation::SGRangeAnimation (SGPropertyNode *prop_root,
|
||||
SGPropertyNode_ptr props)
|
||||
: SGAnimation(props, new ssgRangeSelector),
|
||||
_min(0.0), _max(0.0)
|
||||
_min(0.0), _max(0.0), _min_factor(1.0), _max_factor(1.0)
|
||||
|
||||
{
|
||||
float ranges[2];
|
||||
|
||||
SGPropertyNode_ptr node = props->getChild( "min-property" );
|
||||
SGPropertyNode_ptr node = props->getChild( "min-factor" );
|
||||
if (node != 0) {
|
||||
_min_factor = props->getFloatValue("min-factor", 1.0);
|
||||
}
|
||||
node = props->getChild( "max-factor" );
|
||||
if (node != 0) {
|
||||
_max_factor = props->getFloatValue("max-factor", 1.0);
|
||||
}
|
||||
node = props->getChild( "min-property" );
|
||||
if (node != 0) {
|
||||
_min_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true);
|
||||
ranges[0] = _min_prop->getFloatValue();
|
||||
ranges[0] = _min_prop->getFloatValue() * _min_factor;
|
||||
} else {
|
||||
ranges[0] = _min = props->getFloatValue("min-m", 0);
|
||||
_min = props->getFloatValue("min-m", 0);
|
||||
ranges[0] = _min * _min_factor;
|
||||
}
|
||||
node = props->getChild( "max-property" );
|
||||
if (node != 0) {
|
||||
_max_prop = (SGPropertyNode *)prop_root->getNode(node->getStringValue(), true);
|
||||
ranges[1] = _max_prop->getFloatValue();
|
||||
ranges[1] = _max_prop->getFloatValue() * _max_factor;
|
||||
} else {
|
||||
ranges[1] = _max = props->getFloatValue("max-m", 0);
|
||||
_max = props->getFloatValue("max-m", 0);
|
||||
ranges[1] = _max * _max_factor;
|
||||
}
|
||||
((ssgRangeSelector *)_branch)->setRanges(ranges, 2);
|
||||
}
|
||||
@ -248,20 +259,21 @@ SGRangeAnimation::update()
|
||||
float ranges[2];
|
||||
bool upd = false;
|
||||
if (_min_prop != 0) {
|
||||
ranges[0] = _min_prop->getFloatValue();
|
||||
ranges[0] = _min_prop->getFloatValue() * _min_factor;
|
||||
upd = true;
|
||||
} else {
|
||||
ranges[0] = _min;
|
||||
ranges[0] = _min * _min_factor;
|
||||
}
|
||||
if (_max_prop != 0) {
|
||||
ranges[1] = _max_prop->getFloatValue();
|
||||
ranges[1] = _max_prop->getFloatValue() * _max_factor;
|
||||
upd = true;
|
||||
} else {
|
||||
ranges[1] = _max;
|
||||
ranges[1] = _max * _max_factor;
|
||||
}
|
||||
if (upd)
|
||||
if (upd) {
|
||||
((ssgRangeSelector *)_branch)->setRanges(ranges, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -854,4 +866,45 @@ SGTexMultipleAnimation::update()
|
||||
((ssgTexTrans *)_branch)->setTransform(tmatrix);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of SGAlphaTestAnimation
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SGAlphaTestAnimation::SGAlphaTestAnimation (SGPropertyNode *prop_root,
|
||||
SGPropertyNode_ptr props)
|
||||
: SGAnimation(props, new ssgBranch),
|
||||
_done(false)
|
||||
{
|
||||
_alpha_clamp = props->getFloatValue("alpha-factor", 0.0);
|
||||
}
|
||||
|
||||
SGAlphaTestAnimation::~SGAlphaTestAnimation ()
|
||||
{
|
||||
}
|
||||
|
||||
void SGAlphaTestAnimation::update()
|
||||
{
|
||||
if (!_done) {
|
||||
_done = true;
|
||||
setAlphaClampToBranch(_branch,_alpha_clamp);
|
||||
}
|
||||
}
|
||||
|
||||
void SGAlphaTestAnimation::setAlphaClampToBranch(ssgBranch *b, float clamp)
|
||||
{
|
||||
int nb = b->getNumKids();
|
||||
for (int i = 0; i<nb; i++) {
|
||||
ssgEntity *e = b->getKid(i);
|
||||
if (e->isAKindOf(ssgTypeLeaf())) {
|
||||
ssgSimpleState*s = (ssgSimpleState*)((ssgLeaf*)e)->getState();
|
||||
s->enable( GL_ALPHA_TEST );
|
||||
s->setAlphaClamp( clamp );
|
||||
} else if (e->isAKindOf(ssgTypeBranch())) {
|
||||
setAlphaClampToBranch( (ssgBranch*)e, clamp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// end of animation.cxx
|
||||
|
@ -108,6 +108,8 @@ private:
|
||||
SGPropertyNode_ptr _max_prop;
|
||||
float _min;
|
||||
float _max;
|
||||
float _min_factor;
|
||||
float _max_factor;
|
||||
};
|
||||
|
||||
|
||||
@ -379,4 +381,21 @@ private:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* An animation to enable the alpha test
|
||||
*/
|
||||
class SGAlphaTestAnimation : public SGAnimation
|
||||
{
|
||||
public:
|
||||
SGAlphaTestAnimation (SGPropertyNode *prop_root,
|
||||
SGPropertyNode_ptr props);
|
||||
virtual ~SGAlphaTestAnimation ();
|
||||
virtual void update();
|
||||
private:
|
||||
void setAlphaClampToBranch(ssgBranch *b, float clamp);
|
||||
bool _done;
|
||||
float _alpha_clamp;
|
||||
};
|
||||
|
||||
|
||||
#endif // _SG_ANIMATION_HXX
|
||||
|
@ -130,6 +130,8 @@ sgMakeAnimation( ssgBranch * model,
|
||||
animation = new SGTexMultipleAnimation(prop_root, node);
|
||||
} else if (!strcmp("blend", type)) {
|
||||
animation = new SGBlendAnimation(prop_root, node);
|
||||
} else if (!strcmp("alpha-test", type)) {
|
||||
animation = new SGAlphaTestAnimation(prop_root, node);
|
||||
} else {
|
||||
animation = new SGNullAnimation(node);
|
||||
SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
|
||||
|
Loading…
Reference in New Issue
Block a user