From KOS, "New classes for osgAnimation presented: UpdateFloatUniform, UpdateVec3fUniform and UpdateMatrixfUniform (based on UpdateUniform template)

Classes operate like osgAnimation::UpdateMaterial for Material's diffuse component, but change Uniform."


git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14890 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2015-06-03 09:14:35 +00:00
parent fd806293be
commit fd46645ade
6 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,97 @@
#ifndef OSGANIMATION_UPDATE_UNIFORM
#define OSGANIMATION_UPDATE_UNIFORM 1
#include <osgAnimation/AnimationUpdateCallback>
#include <osgAnimation/Export>
#include <osg/NodeVisitor>
#include <osg/Uniform>
namespace osgAnimation
{
template <typename T>
class OSGANIMATION_EXPORT UpdateUniform : public AnimationUpdateCallback<osg::UniformCallback>
{
protected:
osg::ref_ptr< TemplateTarget<T> > _uniformTarget;
public:
UpdateUniform(const std::string& aName = "")
: AnimationUpdateCallback<osg::UniformCallback>(aName)
{
_uniformTarget = new TemplateTarget<T>(); // NOTE: initial value is undefined
}
UpdateUniform(const UpdateUniform& updateuniform,
const osg::CopyOp& copyop) :
AnimationUpdateCallback<osg::UniformCallback>(updateuniform, copyop)
{
_uniformTarget = new TemplateTarget<T>(*(updateuniform._uniformTarget));
}
META_Object(osgAnimation, UpdateUniform<T>);
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator () (osg::Uniform* uniform, osg::NodeVisitor* nv)
{
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
update(*uniform);
traverse(uniform, nv);
}
bool link(Channel* channel)
{
if (channel->getName().find("uniform") != std::string::npos)
return channel->setTarget(_uniformTarget);
else
OSG_WARN << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class " << className() << std::endl;
return false;
}
void update(osg::Uniform& uniform)
{
T value = _uniformTarget->getValue();
uniform.set(value);
}
};
// float
struct UpdateFloatUniform : public UpdateUniform<float>
{
UpdateFloatUniform(const std::string& aName = "") : UpdateUniform<float>(aName) { }
UpdateFloatUniform(const UpdateFloatUniform& ufu,
const osg::CopyOp& copyop) :
osg::Object(ufu, copyop), // copy name
UpdateUniform<float>(ufu, copyop) { }
META_Object(osgAnimation, UpdateFloatUniform);
};
// Vec3f
struct UpdateVec3fUniform : public UpdateUniform<osg::Vec3f>
{
UpdateVec3fUniform(const std::string& aName = "") : UpdateUniform<osg::Vec3f>(aName) { }
UpdateVec3fUniform(const UpdateVec3fUniform& uv3fu,
const osg::CopyOp& copyop) :
osg::Object(uv3fu, copyop), // copy name
UpdateUniform<osg::Vec3f>(uv3fu, copyop) { }
META_Object(osgAnimation, UpdateVec3fUniform);
};
// Matrixf
struct UpdateMatrixfUniform : public UpdateUniform<osg::Matrixf>
{
UpdateMatrixfUniform(const std::string& aName = "") : UpdateUniform<osg::Matrixf>(aName) { }
UpdateMatrixfUniform(const UpdateMatrixfUniform& umfu,
const osg::CopyOp& copyop) :
osg::Object(umfu, copyop), // copy name
UpdateUniform<osg::Matrixf>(umfu, copyop) { }
META_Object(osgAnimation, UpdateMatrixfUniform);
};
}
#endif

View File

@ -51,6 +51,7 @@ SET(TARGET_H
${HEADER_PATH}/UpdateBone
${HEADER_PATH}/UpdateMaterial
${HEADER_PATH}/UpdateMatrixTransform
${HEADER_PATH}/UpdateUniform
${HEADER_PATH}/Vec3Packed
${HEADER_PATH}/VertexInfluence
)

View File

@ -28,6 +28,10 @@ USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMorph)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateSkeleton)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMorphGeometry)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateRigGeometry)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateFloatUniform)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateMatrixfUniform)
USE_SERIALIZER_WRAPPER(osgAnimation_UpdateVec3fUniform)
extern "C" void wrapper_serializer_library_osgAnimation(void) {}

View File

@ -0,0 +1,17 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/UpdateUniform>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateFloatUniform,
new osgAnimation::UpdateFloatUniform,
osgAnimation::UpdateFloatUniform,
"osg::Object osg::Callback osg::UniformCallback osgAnimation::UpdateFloatUniform" )
{
}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast

View File

@ -0,0 +1,17 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/UpdateUniform>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateMatrixfUniform,
new osgAnimation::UpdateMatrixfUniform,
osgAnimation::UpdateMatrixfUniform,
"osg::Object osg::Callback osg::UniformCallback osgAnimation::UpdateMatrixfUniform" )
{
}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast

View File

@ -0,0 +1,17 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osgAnimation/UpdateUniform>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( osgAnimation_UpdateVec3fUniform,
new osgAnimation::UpdateVec3fUniform,
osgAnimation::UpdateVec3fUniform,
"osg::Object osg::Callback osg::UniformCallback osgAnimation::UpdateVec3fUniform" )
{
}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast