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

Revision 11009, 4.8 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++-*-
[10693]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.
13*/
14
15#ifndef OSGANIMATION_RIGGEOMETRY_H
16#define OSGANIMATION_RIGGEOMETRY_H
17
[9094]18#include <osgAnimation/Export>
[9093]19#include <osgAnimation/Skeleton>
[10693]20#include <osgAnimation/RigTransform>
[11009]21#include <osgAnimation/VertexInfluence>
[9093]22#include <osg/Geometry>
23
24namespace osgAnimation
25{
26
[9094]27    class OSGANIMATION_EXPORT RigGeometry : public osg::Geometry
[9093]28    {
29    public:
30
[9737]31        RigGeometry();
[11009]32//        RigGeometry(const osg::Geometry& b);
[9737]33        RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
34
35        META_Object(osgAnimation, RigGeometry);
36
[10693]37        void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
38        const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}
39        VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}
[9737]40 
41        const Skeleton* getSkeleton() const;
42        Skeleton* getSkeleton();
[10693]43        // will be used by the update callback to init correctly the rig mesh
44        void setSkeleton(Skeleton*);
[9737]45       
46        void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;}
47        bool getNeedToComputeMatrix() const { return _needToComputeMatrix;}
48       
[10693]49
50        // this build the internal database about vertex influence and bones
51        void buildVertexInfluenceSet();
52        const VertexInfluenceSet& getVertexInfluenceSet() const;
53
[9737]54        void computeMatrixFromRootSkeleton();
55
56
[10693]57        // set implementation of rig method
58        void setRigTransformImplementation(RigTransform*);
59        RigTransform* getRigTransformImplementation();
[9737]60
[10693]61        virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
62        void update();
63
64        const osg::Matrix& getMatrixFromSkeletonToGeometry() const;
65        const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const;
66
[11009]67        osg::Geometry* getSourceGeometry();
68        const osg::Geometry* getSourceGeometry() const;
69        void setSourceGeometry(osg::Geometry* geometry);
70
71        void copyFrom(osg::Geometry& from);
72
[9737]73    protected:
[11009]74       
75        osg::ref_ptr<osg::Geometry> _geometry;
[10693]76        osg::ref_ptr<RigTransform> _rigTransformImplementation;
[9737]77
[10693]78        VertexInfluenceSet _vertexInfluenceSet;
79        osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap;
[9737]80
81        osg::Matrix _matrixFromSkeletonToGeometry;
82        osg::Matrix _invMatrixFromSkeletonToGeometry;
83        osg::observer_ptr<Skeleton> _root;
84        bool _needToComputeMatrix;
85 
[9093]86        struct FindNearestParentSkeleton : public osg::NodeVisitor
87        {
[10693]88            osg::ref_ptr<Skeleton> _root;
[9093]89            FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
90            void apply(osg::Transform& node)
91            {
92                if (_root.valid())
93                    return;
94                _root = dynamic_cast<osgAnimation::Skeleton*>(&node);
95                traverse(node);
96            }
97        };
98
99
[9370]100        struct UpdateVertex : public osg::Drawable::UpdateCallback
[9093]101        {
[9370]102            virtual void update(osg::NodeVisitor*, osg::Drawable* drw)
[9093]103            {
104                RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
105                if (!geom)
106                    return;
[10344]107                if (!geom->getSkeleton() && !geom->getParents().empty())
[9093]108                {
109                    FindNearestParentSkeleton finder;
110                    if (geom->getParents().size() > 1)
111                        osg::notify(osg::WARN) << "A RigGeometry should not have multi parent ( " << geom->getName() << " )" << std::endl;
112                    geom->getParents()[0]->accept(finder);
113
114                    if (!finder._root.valid())
[11009]115                    {
116                        osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeomtry ( " << geom->getName() << " )" << std::endl;
[9093]117                        return;
[11009]118                    }
[10693]119                    geom->buildVertexInfluenceSet();
120                    geom->setSkeleton(finder._root.get());
[9093]121                }
122
123                if (!geom->getSkeleton())
124                    return;
125
126                if (geom->getNeedToComputeMatrix())
127                    geom->computeMatrixFromRootSkeleton();
128
[10693]129                geom->update();
[9093]130            }
131        };
[9737]132   };
[9093]133
134}
135
136#endif
Note: See TracBrowser for help on using the browser.