Changeset 10693 for OpenSceneGraph/trunk/include/osgAnimation/RigGeometry
- Timestamp:
- 10/27/09 16:37:13 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgAnimation/RigGeometry
r10344 r10693 1 1 /* -*-c++-*- 2 * Copyright (C) 2008 Cedric Pinson < mornifle@plopbyte.net>2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net> 3 3 * 4 4 * This library is open source and may be redistributed and/or modified under … … 17 17 18 18 #include <osgAnimation/Export> 19 #include <osgAnimation/Skinning>20 19 #include <osgAnimation/Skeleton> 20 #include <osgAnimation/RigTransform> 21 21 #include <osg/Geometry> 22 22 … … 34 34 META_Object(osgAnimation, RigGeometry); 35 35 36 void setInfluenceMap( osgAnimation::VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }37 const osgAnimation::VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}38 osgAnimation::VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}36 void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; } 37 const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();} 38 VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();} 39 39 40 40 const Skeleton* getSkeleton() const; 41 41 Skeleton* getSkeleton(); 42 // will be used by the update callback to init correctly the rig mesh 43 void setSkeleton(Skeleton*); 42 44 43 45 void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;} 44 46 bool getNeedToComputeMatrix() const { return _needToComputeMatrix;} 45 47 46 void buildVertexSet(); 47 void buildTransformer(Skeleton* root); 48 49 // this build the internal database about vertex influence and bones 50 void buildVertexInfluenceSet(); 51 const VertexInfluenceSet& getVertexInfluenceSet() const; 52 48 53 void computeMatrixFromRootSkeleton(); 49 54 50 virtual void transformSoftwareMethod();51 const osgAnimation::VertexInfluenceSet& getVertexInfluenceSet() const { return _vertexInfluenceSet;}52 55 53 const std::vector<osg::Vec3>& getPositionSource() const { return _positionSource;} 54 const std::vector<osg::Vec3>& getNormalSource() const { return _normalSource;} 56 // set implementation of rig method 57 void setRigTransformImplementation(RigTransform*); 58 RigTransform* getRigTransformImplementation(); 59 60 virtual void drawImplementation(osg::RenderInfo& renderInfo) const; 61 void update(); 62 63 const osg::Matrix& getMatrixFromSkeletonToGeometry() const; 64 const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const; 55 65 56 66 protected: 57 67 58 std::vector<osg::Vec3> _positionSource; 59 std::vector<osg::Vec3> _normalSource; 68 osg::ref_ptr<RigTransform> _rigTransformImplementation; 60 69 61 osgAnimation::VertexInfluenceSet _vertexInfluenceSet; 62 osg::ref_ptr<osgAnimation::VertexInfluenceMap> _vertexInfluenceMap; 63 osgAnimation::TransformVertexFunctor _transformVertexes; 70 VertexInfluenceSet _vertexInfluenceSet; 71 osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap; 64 72 65 73 osg::Matrix _matrixFromSkeletonToGeometry; … … 67 75 osg::observer_ptr<Skeleton> _root; 68 76 bool _needToComputeMatrix; 69 70 77 71 78 struct FindNearestParentSkeleton : public osg::NodeVisitor 72 79 { 73 osg::ref_ptr< osgAnimation::Skeleton> _root;80 osg::ref_ptr<Skeleton> _root; 74 81 FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {} 75 82 void apply(osg::Transform& node) … … 99 106 if (!finder._root.valid()) 100 107 return; 101 geom->buildVertex Set();102 geom-> buildTransformer(finder._root.get());108 geom->buildVertexInfluenceSet(); 109 geom->setSkeleton(finder._root.get()); 103 110 } 104 111 … … 108 115 if (geom->getNeedToComputeMatrix()) 109 116 geom->computeMatrixFromRootSkeleton(); 110 geom->transformSoftwareMethod(); 117 118 geom->update(); 111 119 } 112 120 }; 113 114 /** BuildVertexTransformerVisitor is used to setup RigGeometry drawable115 * throw a subgraph.116 */117 struct BuildVertexTransformerVisitor : public osg::NodeVisitor118 {119 osg::ref_ptr<Skeleton> _root;120 BuildVertexTransformerVisitor(Skeleton* root): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _root = root;}121 122 META_NodeVisitor("osgAnimation","BuildVertexTransformerVisitor")123 124 void apply(osg::Geode& node)125 {126 int num = node.getNumDrawables();127 for (int i = 0; i < num; i++) {128 RigGeometry* geom = dynamic_cast<RigGeometry*>(node.getDrawable(i));129 if (geom)130 {131 geom->buildVertexSet();132 geom->buildTransformer(_root.get());133 }134 }135 }136 };137 138 121 }; 139 122
