Create a different default effect for objects that have material animations
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include <simgear/scene/model/model.hxx>
|
#include <simgear/scene/model/model.hxx>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace simgear;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/**
|
/**
|
||||||
@@ -485,6 +486,8 @@ SGMaterialAnimation::createAnimationGroup(osg::Group& parent)
|
|||||||
mat->setDataVariance(osg::Object::DYNAMIC);
|
mat->setDataVariance(osg::Object::DYNAMIC);
|
||||||
unsigned defaultColorModeMask = 0;
|
unsigned defaultColorModeMask = 0;
|
||||||
mat->setUpdateCallback(0); // Just to make sure.
|
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()) {
|
switch (mat->getColorMode()) {
|
||||||
case osg::Material::OFF:
|
case osg::Material::OFF:
|
||||||
defaultColorModeMask = 0;
|
defaultColorModeMask = 0;
|
||||||
@@ -576,3 +579,32 @@ SGMaterialAnimation::install(osg::Node& node)
|
|||||||
}
|
}
|
||||||
defaultAmbientDiffuse = defaultsVisitor.ambientDiffuse;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public:
|
|||||||
const osgDB::ReaderWriter::Options* options);
|
const osgDB::ReaderWriter::Options* options);
|
||||||
virtual osg::Group* createAnimationGroup(osg::Group& parent);
|
virtual osg::Group* createAnimationGroup(osg::Group& parent);
|
||||||
virtual void install(osg::Node& node);
|
virtual void install(osg::Node& node);
|
||||||
|
static SGPropertyNode_ptr makeEffectProperties(const SGPropertyNode* animProp);
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<osg::Material> defaultMaterial;
|
osg::ref_ptr<osg::Material> defaultMaterial;
|
||||||
osg::Vec4 defaultAmbientDiffuse;
|
osg::Vec4 defaultAmbientDiffuse;
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
#include "particles.hxx"
|
#include "particles.hxx"
|
||||||
#include "model.hxx"
|
#include "model.hxx"
|
||||||
#include "SGText.hxx"
|
#include "SGText.hxx"
|
||||||
|
#include "SGMaterialAnimation.hxx"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
@@ -145,31 +146,42 @@ void makeEffectAnimations(PropertyList& animation_nodes,
|
|||||||
for (PropertyList::iterator itr = animation_nodes.begin();
|
for (PropertyList::iterator itr = animation_nodes.begin();
|
||||||
itr != animation_nodes.end();
|
itr != animation_nodes.end();
|
||||||
++itr) {
|
++itr) {
|
||||||
|
SGPropertyNode_ptr effectProp;
|
||||||
SGPropertyNode* animProp = itr->ptr();
|
SGPropertyNode* animProp = itr->ptr();
|
||||||
SGPropertyNode* typeProp = animProp->getChild("type");
|
SGPropertyNode* typeProp = animProp->getChild("type");
|
||||||
if (!typeProp || strcmp(typeProp->getStringValue(), "shader"))
|
if (!typeProp)
|
||||||
continue;
|
continue;
|
||||||
SGPropertyNode* shaderProp = animProp->getChild("shader");
|
const char* typeString = typeProp->getStringValue();
|
||||||
if (!shaderProp || strcmp(shaderProp->getStringValue(), "chrome"))
|
if (!strcmp(typeString, "material")) {
|
||||||
continue;
|
effectProp
|
||||||
*itr = 0;
|
= SGMaterialAnimation::makeEffectProperties(animProp);
|
||||||
SGPropertyNode* textureProp = animProp->getChild("texture");
|
} else if (!strcmp(typeString, "shader")) {
|
||||||
if (!textureProp)
|
|
||||||
continue;
|
SGPropertyNode* shaderProp = animProp->getChild("shader");
|
||||||
SGPropertyNode_ptr effectProp = new SGPropertyNode();
|
if (!shaderProp || strcmp(shaderProp->getStringValue(), "chrome"))
|
||||||
makeChild(effectProp.ptr(), "inherits-from")
|
continue;
|
||||||
->setValue("Effects/chrome");
|
*itr = 0; // effect replaces animation
|
||||||
SGPropertyNode* paramsProp = makeChild(effectProp.get(), "parameters");
|
SGPropertyNode* textureProp = animProp->getChild("texture");
|
||||||
makeChild(paramsProp, "chrome-texture")
|
if (!textureProp)
|
||||||
->setValue(textureProp->getStringValue());
|
continue;
|
||||||
PropertyList objectNameNodes = animProp->getChildren("object-name");
|
effectProp = new SGPropertyNode();
|
||||||
for (PropertyList::iterator objItr = objectNameNodes.begin(),
|
makeChild(effectProp.ptr(), "inherits-from")
|
||||||
end = objectNameNodes.end();
|
->setValue("Effects/chrome");
|
||||||
objItr != end;
|
SGPropertyNode* paramsProp = makeChild(effectProp.get(), "parameters");
|
||||||
++objItr)
|
makeChild(paramsProp, "chrome-texture")
|
||||||
effectProp->addChild("object-name")
|
->setValue(textureProp->getStringValue());
|
||||||
->setStringValue((*objItr)->getStringValue());
|
}
|
||||||
effect_nodes.push_back(effectProp);
|
if (effectProp.valid()) {
|
||||||
|
PropertyList objectNameNodes = animProp->getChildren("object-name");
|
||||||
|
for (PropertyList::iterator objItr = objectNameNodes.begin(),
|
||||||
|
end = objectNameNodes.end();
|
||||||
|
objItr != end;
|
||||||
|
++objItr)
|
||||||
|
effectProp->addChild("object-name")
|
||||||
|
->setStringValue((*objItr)->getStringValue());
|
||||||
|
effect_nodes.push_back(effectProp);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
animation_nodes.erase(remove_if(animation_nodes.begin(),
|
animation_nodes.erase(remove_if(animation_nodes.begin(),
|
||||||
animation_nodes.end(),
|
animation_nodes.end(),
|
||||||
|
|||||||
Reference in New Issue
Block a user