| [11009] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgAnimation/UpdateMaterial> |
|---|
| 16 | #include <osg/NodeVisitor> |
|---|
| 17 | |
|---|
| 18 | using namespace osgAnimation; |
|---|
| 19 | |
|---|
| 20 | UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop) |
|---|
| 21 | : osg::Object(apc, copyop), |
|---|
| 22 | AnimationUpdateCallback<osg::StateAttributeCallback>(apc, copyop) |
|---|
| 23 | { |
|---|
| 24 | _diffuse = new osgAnimation::Vec4Target(apc._diffuse->getValue()); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | UpdateMaterial::UpdateMaterial(const std::string& name): |
|---|
| 28 | AnimationUpdateCallback<osg::StateAttributeCallback>(name) |
|---|
| 29 | { |
|---|
| 30 | _diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1)); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | void UpdateMaterial::operator()(osg::StateAttribute* sa, osg::NodeVisitor* nv) |
|---|
| 35 | { |
|---|
| 36 | if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) |
|---|
| 37 | { |
|---|
| 38 | osg::Material* material = dynamic_cast<osg::Material*>(sa); |
|---|
| 39 | if (material) |
|---|
| 40 | update(*material); |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | osgAnimation::Vec4Target* UpdateMaterial::getDiffuse() { return _diffuse.get(); } |
|---|
| 46 | void UpdateMaterial::update(osg::Material& material) |
|---|
| 47 | { |
|---|
| 48 | osg::Vec4 diffuse = _diffuse->getValue(); |
|---|
| 49 | material.setDiffuse(osg::Material::FRONT_AND_BACK, diffuse); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | bool UpdateMaterial::link(osgAnimation::Channel* channel) |
|---|
| 53 | { |
|---|
| 54 | if (channel->getName().find("diffuse") != std::string::npos) |
|---|
| 55 | { |
|---|
| 56 | return channel->setTarget(_diffuse.get()); |
|---|
| 57 | } |
|---|
| 58 | else |
|---|
| 59 | { |
|---|
| 60 | osg::notify(osg::WARN) << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl; |
|---|
| 61 | } |
|---|
| 62 | return false; |
|---|
| 63 | } |
|---|