Exemplo n.º 1
0
        void                                apply( osg::MatrixTransform& mt )
                                            {
                                                if ( !mt.getUpdateCallback() )
                                                    mt.traverse( *this );

                                                osg::AnimationPathCallback* p_ncb = dynamic_cast< osg::AnimationPathCallback* >( mt.getUpdateCallback() );
                                                if ( !p_ncb )
                                                    mt.traverse( *this );

                                                _p_animPath = p_ncb->getAnimationPath();
                                                if ( !_p_animPath )
                                                    mt.traverse( *this );
                                            }
Exemplo n.º 2
0
//MATRIX
void daeWriter::apply( osg::MatrixTransform &node )
{
#ifdef _DEBUG
    debugPrint( node );
#endif
    updateCurrentDaeNode();
    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) );
    std::string nodeName = getNodeName(node,"matrixTransform");
    currentNode->setId(nodeName.c_str());

    osg::Callback* ncb = node.getUpdateCallback();
    bool handled = false;
    if (ncb)
    {
        osgAnimation::UpdateMatrixTransform* ut = dynamic_cast<osgAnimation::UpdateMatrixTransform*>(ncb);
        // If targeted by an animation we split up the matrix into multiple place element so they can be targeted individually
        if (ut)
        {
            handled = true;

            const osg::Matrix &mat = node.getMatrix();

            // Note: though this is a generic matrix, based on the fact that it will be animated by and UpdateMatrixTransform,
            // we assume the initial matrix can be decomposed into translation, rotation and scale elements
            writeUpdateTransformElements(mat.getTrans(), mat.getRotate(), mat.getScale());
        }
    }

    // If not targeted by an animation simply write a single matrix place element
    if (!handled)
    {
        domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) );
        nodeName += "_matrix";
        mat->setSid(nodeName.c_str());

        const osg::Matrix::value_type *mat_vals = node.getMatrix().ptr();
        for ( int i = 0; i < 4; i++ )
        {
            for ( int j = 0; j < 4; j++ )
            {
                mat->getValue().append( mat_vals[i + j*4] );
            }
        }
    }

    lastDepth = _nodePath.size();

    writeNodeExtra(node);

    traverse( node );
}
void AnimationCleanerVisitor::apply(osg::MatrixTransform& transform) {
    HasGeometryVisitor hasData;
    transform.traverse(hasData);

    if(!hasData.geometry) {
        // if animation transforms have no child geometry they are cleanable
        osgAnimation::Skeleton* skeleton = dynamic_cast<osgAnimation::Skeleton*>(&transform);
        osgAnimation::Bone* bone = dynamic_cast<osgAnimation::Bone*>(&transform);
        if(skeleton) {
            _transforms.push_back(osg::ref_ptr<osgAnimation::Skeleton>(skeleton));
        }
        if(bone) {
            _transforms.push_back(osg::ref_ptr<osgAnimation::Bone>(bone));
        }
    }

    osgAnimation::UpdateMatrixTransform* update = getCallbackType<osgAnimation::UpdateMatrixTransform>(transform.getUpdateCallback());
    if(update) {
        _updates[update] = osg::ref_ptr<osg::Node>(&transform);
    }

    traverse(transform);
}