Ejemplo n.º 1
0
void RigTransformSoftware::operator()(RigGeometry& geom)
{
    if (_needInit)
        if (!init(geom))
            return;

    if (!geom.getSourceGeometry()) {
        OSG_WARN << this << " RigTransformSoftware no source geometry found on RigGeometry" << std::endl;
        return;
    }
    osg::Geometry& source = *geom.getSourceGeometry();
    osg::Geometry& destination = geom;

    osg::Vec3Array* positionSrc = dynamic_cast<osg::Vec3Array*>(source.getVertexArray());
    osg::Vec3Array* positionDst = dynamic_cast<osg::Vec3Array*>(destination.getVertexArray());
    if (positionSrc && (!positionDst || (positionDst->size() != positionSrc->size()) ) )
    {
        if (!positionDst)
        {
            positionDst = new osg::Vec3Array;
            positionDst->setDataVariance(osg::Object::DYNAMIC);
            destination.setVertexArray(positionDst);
        }
        *positionDst = *positionSrc;
    }
    
    osg::Vec3Array* normalSrc = dynamic_cast<osg::Vec3Array*>(source.getNormalArray());
    osg::Vec3Array* normalDst = dynamic_cast<osg::Vec3Array*>(destination.getNormalArray());
    if (normalSrc && (!normalDst || (normalDst->size() != normalSrc->size()) ) )
    {
        if (!normalDst)
        {
            normalDst = new osg::Vec3Array;
            normalDst->setDataVariance(osg::Object::DYNAMIC);
            destination.setNormalArray(normalDst);
            destination.setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
        }
        *normalDst = *normalSrc;
    }

    if (positionDst && !positionDst->empty())
    {
        compute<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), 
                           geom.getInvMatrixFromSkeletonToGeometry(),  
                           &positionSrc->front(),
                           &positionDst->front());
        positionDst->dirty();
    }

    if (normalDst && !normalDst->empty())
    {
        computeNormal<osg::Vec3>(geom.getMatrixFromSkeletonToGeometry(), 
                           geom.getInvMatrixFromSkeletonToGeometry(),  
                           &normalSrc->front(),
                           &normalDst->front());
        normalDst->dirty();
    }
}
void RigTransformHardware::operator()(RigGeometry& geom)
{
    if (_needInit)
        if (!init(geom))
            return;
    computeMatrixPaletteUniform(geom.getMatrixFromSkeletonToGeometry(), geom.getInvMatrixFromSkeletonToGeometry());
}