root/OpenSceneGraph/trunk/include/osgAnimation/Sampler @ 11009

Revision 11009, 5.0 kB (checked in by robert, 5 years ago)

From Cedric Pinson, "Here a list of changes:
Bone now inherit from MatrixTransform?. It simplify a lot the update of
Bone matrix. It helps to have the bone system more generic. eg it's now
possible to have animation data with precomputed bind matrix. The other
benefit, is now the collada plugin will be able to use osgAnimation to
display skinned mesh. Michael Plating did a great work to improve this
aspect, he is working on the collada plugin and should be able to submit
a new version soon.
The RigGeometry? has been refactored so now it works when you save and
reload RigGeometry? because the source is not touched anymore. The
benefit with this update is that it should be now possible to use a
MorphGeometry? as source for a RigGeometry?.

The bad news is that the format has changed, so i have rebuild osg-data
related to osgAnimation data, updated the blender exporter to export to
the new format.
The fbx plugin could be touched about this commit, i dont compile it so
i can't give more information about it.
The bvh plugin has been updated by Wang rui so this one is fixed with
the new code of osgAnimation.
The examples has been updated to work with the new code too...

The example osg-data/example.osg should be remove, it's an old example
that does not work.

For people using blender the blender exporter up to date is here:
http://hg.plopbyte.net/osgexport2/
it will be merge to http://hg.plopbyte.net/osgexport/ as soon as the
modification will be push in the trunk.
"

RevLine 
[9093]1/*  -*-c++-*-
[10527]2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
[9093]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.
[10527]13 *
14 * Authors:
15 *         Cedric Pinson <cedric.pinson@plopbyte.net>
16 *         Michael Platings <mplatings@pixelpower.com>
17 */
[9093]18
19#ifndef OSGANIMATION_SAMPLER_H
20#define OSGANIMATION_SAMPLER_H
21
22#include <vector>
23#include <iostream>
24#include <osg/Referenced>
25#include <osg/ref_ptr>
26#include <osgAnimation/Keyframe>
27#include <osgAnimation/Interpolator>
28
29namespace osgAnimation
30{
31
32    class Sampler : public osg::Referenced
33    {
34    public:
35        virtual KeyframeContainer* getKeyframeContainer() = 0;
36        virtual const KeyframeContainer* getKeyframeContainer() const = 0;
37    protected:
38    };
39
40    // Sampler generic
41    template <class F>
42    class TemplateSampler : public Sampler
43    {
44    public:
45        typedef typename F::KeyframeType KeyframeType;
46        typedef TemplateKeyframeContainer<KeyframeType> KeyframeContainerType;
47        typedef typename F::UsingType UsingType;
48        typedef F FunctorType;
49
50        TemplateSampler() {}
51        ~TemplateSampler() {}
52
53        void getValueAt(float time, UsingType& result) const { _functor.getValue(*_keyframes, time, result);}
54        void setKeyframeContainer(KeyframeContainerType* kf) { _keyframes = kf;}
55
56        virtual KeyframeContainer* getKeyframeContainer() { return _keyframes.get(); }
57        virtual const KeyframeContainer* getKeyframeContainer() const { return _keyframes.get();}
58
59        KeyframeContainerType* getKeyframeContainerTyped() { return _keyframes.get();}
60        const KeyframeContainerType* getKeyframeContainerTyped() const { return _keyframes.get();}
61        KeyframeContainerType* getOrCreateKeyframeContainer()
62        {
63            if (_keyframes != 0)
64                return _keyframes.get();
65            _keyframes = new KeyframeContainerType;
66            return _keyframes.get();
67        }
68
69        float getStartTime() const
70        {
[9531]71            if (!_keyframes)
72                return 0.0f;
[9093]73            return _keyframes->front().getTime();
74        }
75
76        float getEndTime() const
77        {
[9531]78            if (!_keyframes)
79                return 0.0f;
[9093]80            return _keyframes->back().getTime();
81        }
82
83    protected:
84
85        FunctorType _functor;
86        osg::ref_ptr<KeyframeContainerType> _keyframes;
87    };
88
89
90    template<typename VALUESAMPLERTYPE, typename TIMESAMPLERTYPE>
91    class TemplateCompositeSampler : public osg::Referenced
92    {
93        VALUESAMPLERTYPE& _value;
94        TIMESAMPLERTYPE& _time;
95
96    public:
97        typedef typename VALUESAMPLERTYPE::FunctorType::UsingType UsingType;
98        typedef typename VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType;
99
100        TemplateCompositeSampler(VALUESAMPLERTYPE& value, TIMESAMPLERTYPE& time) : _value(value), _time(time)
101        {
102        }
103
104        void getValueAt(float time, typename VALUESAMPLERTYPE::FunctorType::UsingType& result)
105        {
106            float newtime;
107            _time.getValueAt(time, newtime);
108            _value.getValueAt(newtime, result);
109        }
110        float getStartTime() const {return _time.getStartTime(); }
111        float getEndTime() const {return _time.getEndTime();}
112    };
113
114
[10527]115    typedef TemplateSampler<DoubleStepInterpolator> DoubleStepSampler;
116    typedef TemplateSampler<FloatStepInterpolator> FloatStepSampler;
117    typedef TemplateSampler<Vec2StepInterpolator> Vec2StepSampler;
118    typedef TemplateSampler<Vec3StepInterpolator> Vec3StepSampler;
119    typedef TemplateSampler<Vec4StepInterpolator> Vec4StepSampler;
120    typedef TemplateSampler<QuatStepInterpolator> QuatStepSampler;
121
[9093]122    typedef TemplateSampler<DoubleLinearInterpolator> DoubleLinearSampler;
123    typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
124    typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
125    typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
126    typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
127    typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
[11009]128    typedef TemplateSampler<MatrixLinearInterpolator> MatrixLinearSampler;
[10527]129
[9093]130    typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;
131    typedef TemplateSampler<DoubleCubicBezierInterpolator> DoubleCubicBezierSampler;
132    typedef TemplateSampler<Vec2CubicBezierInterpolator> Vec2CubicBezierSampler;
133    typedef TemplateSampler<Vec3CubicBezierInterpolator> Vec3CubicBezierSampler;
134    typedef TemplateSampler<Vec4CubicBezierInterpolator> Vec4CubicBezierSampler;
135 
[9376]136}
[9093]137
138#endif
Note: See TracBrowser for help on using the browser.