root/OpenSceneGraph/trunk/src/osgAnimation/UpdateMaterial.cpp @ 13041

Revision 13041, 2.1 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/*  -*-c++-*-
2 *  Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * OpenSceneGraph Public License for more details.
13 */
14
15#include <osgAnimation/UpdateMaterial>
16#include <osg/NodeVisitor>
17
18using namespace osgAnimation;
19
20UpdateMaterial::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
27UpdateMaterial::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/** Callback method called by the NodeVisitor when visiting a node.*/
34void 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
45osgAnimation::Vec4Target* UpdateMaterial::getDiffuse() { return _diffuse.get(); }
46void UpdateMaterial::update(osg::Material& material)
47{
48    osg::Vec4 diffuse = _diffuse->getValue();
49    material.setDiffuse(osg::Material::FRONT_AND_BACK, diffuse);
50}
51
52bool 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_WARN << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl;
61    }
62    return false;
63}
Note: See TracBrowser for help on using the browser.