Show
Ignore:
Timestamp:
01/27/10 13:24:55 (3 years ago)
Author:
robert
Message:

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.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgAnimation/RigTransformSoftware.cpp

    r10693 r11009  
    1414 
    1515 
     16#include <osgAnimation/VertexInfluence> 
    1617#include <osgAnimation/RigTransformSoftware> 
     18#include <osgAnimation/BoneMapVisitor> 
    1719#include <osgAnimation/RigGeometry> 
    1820 
    1921using namespace osgAnimation; 
     22 
     23RigTransformSoftware::RigTransformSoftware() 
     24{ 
     25    _needInit = true; 
     26} 
    2027 
    2128bool RigTransformSoftware::init(RigGeometry& geom) 
     
    2330    if (!geom.getSkeleton()) 
    2431        return false; 
    25     Bone::BoneMap bm = geom.getSkeleton()->getBoneMap(); 
     32 
     33    BoneMapVisitor mapVisitor; 
     34    geom.getSkeleton()->accept(mapVisitor); 
     35    BoneMap bm = mapVisitor.getBoneMap(); 
    2636    initVertexSetFromBones(bm, geom.getVertexInfluenceSet().getUniqVertexSetToBoneSetList()); 
     37 
     38    geom.copyFrom(*geom.getSourceGeometry()); 
     39    geom.setVertexArray(0); 
     40    geom.setNormalArray(0); 
     41 
    2742    _needInit = false; 
    2843    return true; 
    2944} 
    3045 
    31 void RigTransformSoftware::update(RigGeometry& geom) 
     46void RigTransformSoftware::operator()(RigGeometry& geom) 
    3247{ 
    33     osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(geom.getVertexArray()); 
    34     if (pos && _positionSource.size() != pos->size())  
     48    if (_needInit) 
     49        if (!init(geom)) 
     50            return; 
     51 
     52    osg::Geometry& source = *geom.getSourceGeometry(); 
     53    osg::Geometry& destination = geom; 
     54 
     55    osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray()); 
     56    osg::Vec3Array* positionDst = dynamic_cast<osg::Vec3Array*>(destination.getVertexArray()); 
     57    if (positionSrc && (!positionDst || (positionDst->size() != positionSrc->size()) ) ) 
    3558    { 
    36         _positionSource = std::vector<osg::Vec3>(pos->begin(),pos->end()); 
    37         geom.getVertexArray()->setDataVariance(osg::Object::DYNAMIC); 
     59        if (!positionDst) 
     60        { 
     61            positionDst = new osg::Vec3Array; 
     62            positionDst->setDataVariance(osg::Object::DYNAMIC); 
     63            destination.setVertexArray(positionDst); 
     64        } 
     65        *positionDst = *positionSrc; 
    3866    } 
    39     osg::Vec3Array* normal = dynamic_cast<osg::Vec3Array*>(geom.getNormalArray()); 
    40     if (normal && _normalSource.size() != normal->size())  
     67     
     68    osg::Vec3Array* normalSrc = dynamic_cast<osg::Vec3Array*>(source.getNormalArray()); 
     69    osg::Vec3Array* normalDst = dynamic_cast<osg::Vec3Array*>(destination.getNormalArray()); 
     70    if (normalSrc && (!normalDst || (normalDst->size() != normalSrc->size()) ) ) 
    4171    { 
    42         _normalSource = std::vector<osg::Vec3>(normal->begin(),normal->end()); 
    43         geom.getNormalArray()->setDataVariance(osg::Object::DYNAMIC); 
     72        if (!normalDst) 
     73        { 
     74            normalDst = new osg::Vec3Array; 
     75            normalDst->setDataVariance(osg::Object::DYNAMIC); 
     76            destination.setNormalArray(normalDst); 
     77            destination.setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 
     78        } 
     79        *normalDst = *normalSrc; 
    4480    } 
    4581 
    46     if (!_positionSource.empty())  
     82    if (positionDst && !positionDst->empty()) 
    4783    { 
    48         compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry(),  &_positionSource.front(), &pos->front()); 
    49         pos->dirty(); 
     84        compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),  
     85                           geom.getInvMatrixFromSkeletonToGeometry(),   
     86                           &positionSrc->front(), 
     87                           &positionDst->front()); 
     88        positionDst->dirty(); 
    5089    } 
    51     if (!_normalSource.empty())  
     90 
     91    if (normalDst && !normalDst->empty()) 
    5292    { 
    53         computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry(), &_normalSource.front(), &normal->front()); 
    54         normal->dirty(); 
     93        computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(),  
     94                           geom.getInvMatrixFromSkeletonToGeometry(),   
     95                           &normalSrc->front(), 
     96                           &normalDst->front()); 
     97        normalDst->dirty(); 
    5598    } 
    5699} 
    57100 
    58 void RigTransformSoftware::initVertexSetFromBones(const Bone::BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence) 
     101void RigTransformSoftware::initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence) 
    59102{ 
    60103    _boneSetVertexSet.clear(); 
     
    73116            const std::string& bname = inf.getBones()[b].getBoneName(); 
    74117            float weight = inf.getBones()[b].getWeight(); 
    75             Bone::BoneMap::const_iterator it = map.find(bname); 
     118            BoneMap::const_iterator it = map.find(bname); 
    76119            if (it == map.end())  
    77120            {