diff --git a/include/osgAnimation/UpdateUniform b/include/osgAnimation/UpdateUniform new file mode 100644 index 000000000..623a3406b --- /dev/null +++ b/include/osgAnimation/UpdateUniform @@ -0,0 +1,97 @@ +#ifndef OSGANIMATION_UPDATE_UNIFORM +#define OSGANIMATION_UPDATE_UNIFORM 1 + +#include +#include +#include +#include + +namespace osgAnimation +{ + template + class OSGANIMATION_EXPORT UpdateUniform : public AnimationUpdateCallback + { + protected: + osg::ref_ptr< TemplateTarget > _uniformTarget; + + public: + UpdateUniform(const std::string& aName = "") + : AnimationUpdateCallback(aName) + { + _uniformTarget = new TemplateTarget(); // NOTE: initial value is undefined + } + + UpdateUniform(const UpdateUniform& updateuniform, + const osg::CopyOp& copyop) : + AnimationUpdateCallback(updateuniform, copyop) + { + _uniformTarget = new TemplateTarget(*(updateuniform._uniformTarget)); + } + + META_Object(osgAnimation, UpdateUniform); + + /** 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 + { + UpdateFloatUniform(const std::string& aName = "") : UpdateUniform(aName) { } + UpdateFloatUniform(const UpdateFloatUniform& ufu, + const osg::CopyOp& copyop) : + osg::Object(ufu, copyop), // copy name + UpdateUniform(ufu, copyop) { } + + META_Object(osgAnimation, UpdateFloatUniform); + }; + + // Vec3f + struct UpdateVec3fUniform : public UpdateUniform + { + UpdateVec3fUniform(const std::string& aName = "") : UpdateUniform(aName) { } + UpdateVec3fUniform(const UpdateVec3fUniform& uv3fu, + const osg::CopyOp& copyop) : + osg::Object(uv3fu, copyop), // copy name + UpdateUniform(uv3fu, copyop) { } + + META_Object(osgAnimation, UpdateVec3fUniform); + }; + + // Matrixf + struct UpdateMatrixfUniform : public UpdateUniform + { + UpdateMatrixfUniform(const std::string& aName = "") : UpdateUniform(aName) { } + UpdateMatrixfUniform(const UpdateMatrixfUniform& umfu, + const osg::CopyOp& copyop) : + osg::Object(umfu, copyop), // copy name + UpdateUniform(umfu, copyop) { } + + META_Object(osgAnimation, UpdateMatrixfUniform); + }; +} + +#endif diff --git a/src/osgAnimation/CMakeLists.txt b/src/osgAnimation/CMakeLists.txt index ef7373d5b..b0e920544 100644 --- a/src/osgAnimation/CMakeLists.txt +++ b/src/osgAnimation/CMakeLists.txt @@ -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 ) diff --git a/src/osgWrappers/serializers/osgAnimation/LibraryWrapper.cpp b/src/osgWrappers/serializers/osgAnimation/LibraryWrapper.cpp index eb0c473d2..1a793647d 100644 --- a/src/osgWrappers/serializers/osgAnimation/LibraryWrapper.cpp +++ b/src/osgWrappers/serializers/osgAnimation/LibraryWrapper.cpp @@ -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) {} diff --git a/src/osgWrappers/serializers/osgAnimation/UpdateFloatUniform.cpp b/src/osgWrappers/serializers/osgAnimation/UpdateFloatUniform.cpp new file mode 100644 index 000000000..b5cd6b45e --- /dev/null +++ b/src/osgWrappers/serializers/osgAnimation/UpdateFloatUniform.cpp @@ -0,0 +1,17 @@ +#undef OBJECT_CAST +#define OBJECT_CAST dynamic_cast + +#include +#include +#include +#include + +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 diff --git a/src/osgWrappers/serializers/osgAnimation/UpdateMatrixfUniform.cpp b/src/osgWrappers/serializers/osgAnimation/UpdateMatrixfUniform.cpp new file mode 100644 index 000000000..3d6a65b7c --- /dev/null +++ b/src/osgWrappers/serializers/osgAnimation/UpdateMatrixfUniform.cpp @@ -0,0 +1,17 @@ +#undef OBJECT_CAST +#define OBJECT_CAST dynamic_cast + +#include +#include +#include +#include + +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 diff --git a/src/osgWrappers/serializers/osgAnimation/UpdateVec3fUniform.cpp b/src/osgWrappers/serializers/osgAnimation/UpdateVec3fUniform.cpp new file mode 100644 index 000000000..06c4b1802 --- /dev/null +++ b/src/osgWrappers/serializers/osgAnimation/UpdateVec3fUniform.cpp @@ -0,0 +1,17 @@ +#undef OBJECT_CAST +#define OBJECT_CAST dynamic_cast + +#include +#include +#include +#include + +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