Melchior FRANZ:

Re-organisation: <diffuse>, <ambient>, <emission>, <specular> are
now groups with members <red>, <green>, <blue>, <factor>, <offset>,
and their <*-prop> forms. Additionally, there's an option <property-base>
that can be used to set a path that is prepended to all <*-prop> paths.
It defaults to an empty string. Rationale: see model-howto.html.
This commit is contained in:
ehofman
2005-03-28 09:13:45 +00:00
parent 3a8b431a5b
commit 405a455906
2 changed files with 93 additions and 161 deletions
+79 -155
View File
@@ -1118,44 +1118,29 @@ void SGAlphaTestAnimation::setAlphaClampToBranch(ssgBranch *b, float clamp)
SGMaterialAnimation::SGMaterialAnimation( SGPropertyNode *prop_root, SGMaterialAnimation::SGMaterialAnimation( SGPropertyNode *prop_root,
SGPropertyNode_ptr props, const SGPath &texture_path) SGPropertyNode_ptr props, const SGPath &texture_path)
: SGAnimation(props, new ssgBranch), : SGAnimation(props, new ssgBranch),
_base_dir(texture_path), _prop_root(prop_root),
_prop_base(""),
_texture_base(texture_path),
_cached_material(0), _cached_material(0),
_cloned_material(0), _cloned_material(0),
_read(0), _read(0),
_update(0), _update(0),
_global(props->getBoolValue("global", false)) _global(props->getBoolValue("global", false))
{ {
_diff.red = props->getFloatValue("diffuse-red", -1.0); SGPropertyNode_ptr n;
_diff.green = props->getFloatValue("diffuse-green", -1.0); n = props->getChild("condition");
_diff.blue = props->getFloatValue("diffuse-blue", -1.0); _condition = n ? sgReadCondition(_prop_root, n) : 0;
_diff.factor = props->getFloatValue("diffuse-factor", 1.0); n = props->getChild("property-base");
_diff.offset = props->getFloatValue("diffuse-offset", 0.0); if (n) {
if (_diff.dirty()) _prop_base = n->getStringValue();
_update |= DIFFUSE; if (!_prop_base.empty() && _prop_base.end()[-1] != '/')
_prop_base += '/';
}
_amb.red = props->getFloatValue("ambient-red", -1.0); initColorGroup(props->getChild("diffuse"), &_diff, DIFFUSE);
_amb.green = props->getFloatValue("ambient-green", -1.0); initColorGroup(props->getChild("ambient"), &_amb, AMBIENT);
_amb.blue = props->getFloatValue("ambient-blue", -1.0); initColorGroup(props->getChild("emission"), &_emis, EMISSION);
_amb.factor = props->getFloatValue("ambient-factor", 1.0); initColorGroup(props->getChild("specular"), &_spec, SPECULAR);
_amb.offset = props->getFloatValue("ambient-offset", 0.0);
if (_amb.dirty())
_update |= AMBIENT;
_spec.red = props->getFloatValue("specular-red", -1.0);
_spec.green = props->getFloatValue("specular-green", -1.0);
_spec.blue = props->getFloatValue("specular-blue", -1.0);
_spec.factor = props->getFloatValue("specular-factor", 1.0);
_spec.offset = props->getFloatValue("specular-offset", 0.0);
if (_spec.dirty())
_update |= SPECULAR;
_emis.red = props->getFloatValue("emission-red", -1.0);
_emis.green = props->getFloatValue("emission-green", -1.0);
_emis.blue = props->getFloatValue("emission-blue", -1.0);
_emis.factor = props->getFloatValue("emission-factor", 1.0);
_emis.offset = props->getFloatValue("emission-offset", 0.0);
if (_emis.dirty())
_update |= EMISSION;
_shi = props->getFloatValue("shininess", -1.0); _shi = props->getFloatValue("shininess", -1.0);
if (_shi >= 0.0) if (_shi >= 0.0)
@@ -1171,74 +1156,47 @@ SGMaterialAnimation::SGMaterialAnimation( SGPropertyNode *prop_root,
string _texture_str = props->getStringValue("texture", ""); string _texture_str = props->getStringValue("texture", "");
if (!_texture_str.empty()) { if (!_texture_str.empty()) {
_texture = _base_dir; _texture = _texture_base;
_texture.append(_texture_str); _texture.append(_texture_str);
_update |= TEXTURE; _update |= TEXTURE;
} }
SGPropertyNode_ptr node = props->getChild("condition"); n = props->getChild("shininess-prop");
_condition = node ? sgReadCondition(prop_root, node) : 0; _shi_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
n = props->getChild("transparency-prop");
_trans_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;
}
node = props->getChild("diffuse-red-prop"); void SGMaterialAnimation::initColorGroup(SGPropertyNode_ptr group, ColorSpec *col, int flag)
_diff.red_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; {
node = props->getChild("diffuse-green-prop"); if (!group)
_diff.green_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; return;
node = props->getChild("diffuse-blue-prop");
_diff.blue_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("diffuse-factor-prop");
_diff.factor_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("diffuse-offset-prop");
_diff.offset_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
if (_diff.live())
_read |= DIFFUSE;
node = props->getChild("ambient-red-prop"); col->red = group->getFloatValue("red", -1.0);
_amb.red_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; col->green = group->getFloatValue("green", -1.0);
node = props->getChild("ambient-green-prop"); col->blue = group->getFloatValue("blue", -1.0);
_amb.green_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; col->factor = group->getFloatValue("factor", 1.0);
node = props->getChild("ambient-blue-prop"); col->offset = group->getFloatValue("offset", 0.0);
_amb.blue_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; if (col->dirty())
node = props->getChild("ambient-factor-prop"); _update |= flag;
_amb.factor_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("ambient-offset-prop");
_amb.offset_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
if (_amb.live())
_read |= AMBIENT;
node = props->getChild("specular-red-prop"); SGPropertyNode *n;
_spec.red_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; n = group->getChild("red-prop");
node = props->getChild("specular-green-prop"); col->red_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
_spec.green_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; n = group->getChild("green-prop");
node = props->getChild("specular-blue-prop"); col->green_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
_spec.blue_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; n = group->getChild("blue-prop");
node = props->getChild("specular-factor-prop"); col->blue_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
_spec.factor_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; n = group->getChild("factor-prop");
node = props->getChild("specular-offset-prop"); col->factor_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
_spec.offset_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0; n = group->getChild("offset-prop");
if (_spec.live()) col->offset_prop = n ? _prop_root->getNode(path(n->getStringValue()), true) : 0;
_read |= SPECULAR; if (col->live())
_read |= flag;
node = props->getChild("emission-red-prop");
_emis.red_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("emission-green-prop");
_emis.green_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("emission-blue-prop");
_emis.blue_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("emission-factor-prop");
_emis.factor_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("emission-offset-prop");
_emis.offset_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
if (_emis.live())
_read |= EMISSION;
node = props->getChild("shininess-prop");
_shi_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("transparency-prop");
_trans_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("threshold-prop");
_thresh_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
node = props->getChild("texture-prop");
_tex_prop = node ? prop_root->getNode(node->getStringValue(), true) : 0;
} }
void SGMaterialAnimation::init() void SGMaterialAnimation::init()
@@ -1252,66 +1210,15 @@ int SGMaterialAnimation::update()
if (_condition && !_condition->test()) if (_condition && !_condition->test())
return 2; return 2;
if (_read & DIFFUSE) { if (_read & DIFFUSE)
ColorSpec tmp = _diff; updateColorGroup(&_diff, DIFFUSE);
if (_diff.red_prop) if (_read & AMBIENT)
_diff.red = _diff.red_prop->getFloatValue(); updateColorGroup(&_amb, AMBIENT);
if (_diff.green_prop) if (_read & EMISSION)
_diff.green = _diff.green_prop->getFloatValue(); updateColorGroup(&_emis, EMISSION);
if (_diff.blue_prop) if (_read & SPECULAR)
_diff.blue = _diff.blue_prop->getFloatValue(); updateColorGroup(&_spec, SPECULAR);
if (_diff.factor_prop)
_diff.factor = _diff.factor_prop->getFloatValue();
if (_diff.offset_prop)
_diff.offset = _diff.offset_prop->getFloatValue();
if (_diff != tmp)
_update |= DIFFUSE;
}
if (_read & AMBIENT) {
ColorSpec tmp = _amb;
if (_amb.red_prop)
_amb.red = _amb.red_prop->getFloatValue();
if (_amb.green_prop)
_amb.green = _amb.green_prop->getFloatValue();
if (_amb.blue_prop)
_amb.blue = _amb.blue_prop->getFloatValue();
if (_amb.factor_prop)
_amb.factor = _amb.factor_prop->getFloatValue();
if (_amb.offset_prop)
_amb.offset = _amb.offset_prop->getFloatValue();
if (_amb != tmp)
_update |= AMBIENT;
}
if (_read & SPECULAR) {
ColorSpec tmp = _spec;
if (_spec.red_prop)
_spec.red = _spec.red_prop->getFloatValue();
if (_spec.green_prop)
_spec.green = _spec.green_prop->getFloatValue();
if (_spec.blue_prop)
_spec.blue = _spec.blue_prop->getFloatValue();
if (_spec.factor_prop)
_spec.factor = _spec.factor_prop->getFloatValue();
if (_spec.offset_prop)
_spec.offset = _spec.offset_prop->getFloatValue();
if (_spec != tmp)
_update |= SPECULAR;
}
if (_read & EMISSION) {
ColorSpec tmp = _emis;
if (_emis.red_prop)
_emis.red = _emis.red_prop->getFloatValue();
if (_emis.green_prop)
_emis.green = _emis.green_prop->getFloatValue();
if (_emis.blue_prop)
_emis.blue = _emis.blue_prop->getFloatValue();
if (_emis.factor_prop)
_emis.factor = _emis.factor_prop->getFloatValue();
if (_emis.offset_prop)
_emis.offset = _emis.offset_prop->getFloatValue();
if (_emis != tmp)
_update |= EMISSION;
}
float f; float f;
if (_shi_prop) { if (_shi_prop) {
f = _shi; f = _shi;
@@ -1335,7 +1242,7 @@ int SGMaterialAnimation::update()
string t = _tex_prop->getStringValue(); string t = _tex_prop->getStringValue();
if (!t.empty() && t != _texture_str) { if (!t.empty() && t != _texture_str) {
_texture_str = t; _texture_str = t;
_texture = _base_dir; _texture = _texture_base;
_texture.append(t); _texture.append(t);
_update |= TEXTURE; _update |= TEXTURE;
} }
@@ -1347,6 +1254,23 @@ int SGMaterialAnimation::update()
return 2; return 2;
} }
void SGMaterialAnimation::updateColorGroup(ColorSpec *col, int flag)
{
ColorSpec tmp = *col;
if (col->red_prop)
col->red = col->red_prop->getFloatValue();
if (col->green_prop)
col->green = col->green_prop->getFloatValue();
if (col->blue_prop)
col->blue = col->blue_prop->getFloatValue();
if (col->factor_prop)
col->factor = col->factor_prop->getFloatValue();
if (col->offset_prop)
col->offset = col->offset_prop->getFloatValue();
if (*col != tmp)
_update |= flag;
}
void SGMaterialAnimation::cloneMaterials(ssgBranch *b) void SGMaterialAnimation::cloneMaterials(ssgBranch *b)
{ {
for (int i = 0; i < b->getNumKids(); i++) for (int i = 0; i < b->getNumKids(); i++)
@@ -1382,10 +1306,10 @@ void SGMaterialAnimation::setMaterialBranch(ssgBranch *b)
} }
if (_update & AMBIENT) if (_update & AMBIENT)
s->setMaterial(GL_AMBIENT, _amb.rgba()); s->setMaterial(GL_AMBIENT, _amb.rgba());
if (_update & SPECULAR)
s->setMaterial(GL_SPECULAR, _spec.rgba());
if (_update & EMISSION) if (_update & EMISSION)
s->setMaterial(GL_EMISSION, _emis.rgba()); s->setMaterial(GL_EMISSION, _emis.rgba());
if (_update & SPECULAR)
s->setMaterial(GL_SPECULAR, _spec.rgba());
if (_update & SHININESS) if (_update & SHININESS)
s->setShininess(clamp(_shi, 0.0, 128.0)); s->setShininess(clamp(_shi, 0.0, 128.0));
if (_update & TRANSPARENCY) { if (_update & TRANSPARENCY) {
+14 -6
View File
@@ -466,14 +466,14 @@ private:
SGPropertyNode_ptr factor_prop; SGPropertyNode_ptr factor_prop;
SGPropertyNode_ptr offset_prop; SGPropertyNode_ptr offset_prop;
sgVec4 v; sgVec4 v;
bool dirty() { inline bool dirty() {
return red >= 0.0 || green >= 0.0 || blue >= 0.0; return red >= 0.0 || green >= 0.0 || blue >= 0.0;
} }
bool live() { inline bool live() {
return red_prop || green_prop || blue_prop return red_prop || green_prop || blue_prop
|| factor_prop || offset_prop; || factor_prop || offset_prop;
} }
bool operator!=(ColorSpec& a) { inline bool operator!=(ColorSpec& a) {
return red != a.red || green != a.green || blue != a.blue return red != a.red || green != a.green || blue != a.blue
|| factor != a.factor || offset != a.offset; || factor != a.factor || offset != a.offset;
} }
@@ -484,12 +484,14 @@ private:
v[3] = 1.0; v[3] = 1.0;
return v; return v;
} }
float clamp(float val) { inline float clamp(float val) {
return val < 0.0 ? 0.0 : val > 1.0 ? 1.0 : val; return val < 0.0 ? 0.0 : val > 1.0 ? 1.0 : val;
} }
}; };
SGCondition *_condition; SGCondition *_condition;
SGPath _base_dir; SGPropertyNode *_prop_root;
string _prop_base;
SGPath _texture_base;
SGPath _texture; SGPath _texture;
string _texture_str; string _texture_str;
ssgSimpleState* _cached_material; ssgSimpleState* _cached_material;
@@ -505,6 +507,7 @@ private:
float _trans; float _trans;
float _thresh; // alpha_clamp (see man glAlphaFunc) float _thresh; // alpha_clamp (see man glAlphaFunc)
string _tex; string _tex;
string _tmpstr;
SGPropertyNode_ptr _shi_prop; SGPropertyNode_ptr _shi_prop;
SGPropertyNode_ptr _trans_prop; SGPropertyNode_ptr _trans_prop;
SGPropertyNode_ptr _thresh_prop; SGPropertyNode_ptr _thresh_prop;
@@ -512,9 +515,14 @@ private:
void cloneMaterials(ssgBranch *b); void cloneMaterials(ssgBranch *b);
void setMaterialBranch(ssgBranch *b); void setMaterialBranch(ssgBranch *b);
float clamp(float val, float min = 0.0, float max = 1.0) { void initColorGroup(SGPropertyNode_ptr, ColorSpec *, int flag);
void updateColorGroup(ColorSpec *, int flag);
inline float clamp(float val, float min = 0.0, float max = 1.0) {
return val < min ? min : val > max ? max : val; return val < min ? min : val > max ? max : val;
} }
const char *path(const char *rel) {
return (_tmpstr = _prop_base + rel).c_str();
}
}; };