//
//  Since OpenFlight doesn't have 'Sequence' records---just Group records that
//  may, optionally, be animated---this routine sets the animation-related
//  parameters for a Group record and simply forwards to writeGroup()
//
void
FltExportVisitor::writeSequence(const osg::Sequence &sequence)
{
    int32   flags        = 0, loopCount = 0;
    float32 loopDuration = 0.0f, lastFrameDuration = 0.0f;

    osg::Sequence::LoopMode mode;
    int                     firstChildDisplayed, lastChildDisplayed;

    sequence.getInterval(mode, firstChildDisplayed, lastChildDisplayed);

    if (firstChildDisplayed == 0)
    {
        flags |= FORWARD_ANIM;
    }

    else
    {
        flags &= ~FORWARD_ANIM;
    }

    if (mode == osg::Sequence::SWING)
    {
        flags |= SWING_ANIM;
    }

    else
    {
        flags &= ~SWING_ANIM;
    }

    // Do we loop infinitely, or only a certain number of times?
    float speedUp;
    int   numReps;
    sequence.getDuration(speedUp, numReps);

    if (numReps != -1)
    {
        loopCount = numReps;
    }

    else
    {
        loopCount = 0;  // == loop continuously
    }

    // Sum individual frame durations to get the total loopDuration
    for (unsigned int i = 0; i < sequence.getNumChildren(); ++i)
    {
        loopDuration += sequence.getTime(i);
    }

    lastFrameDuration = sequence.getLastFrameTime();

    writeGroup(sequence, flags, loopCount, loopDuration, lastFrameDuration);
}
示例#2
0
void daeWriter::apply( osg::Sequence &node )
{
    debugPrint( node );
    updateCurrentDaeNode();
    currentNode = daeSafeCast< domNode >(currentNode->add( COLLADA_ELEMENT_NODE ) );
    currentNode->setId(getNodeName(node,"sequence").c_str());

    // If a sequence node, store it's data as extra "Sequence" data in the "OpenSceneGraph" technique
    if (writeExtras)
    {
        // Adds the following to a node

        //<extra type="Sequence">
        //    <technique profile="OpenSceneGraph">
        //        <FrameTime>0 0</FrameTime>
        //        <LastFrameTime>0</LastFrameTime>
        //        <LoopMode>0</LoopMode>
        //        <IntervalBegin>0</IntervalBegin>
        //        <IntervalEnd>-1</IntervalEnd>
        //        <DurationSpeed>1</DurationSpeed>
        //        <DurationNReps>-1</DurationNReps>
        //        <SequenceMode>0</SequenceMode>
        //    </technique>
        //</extra>

        domExtra *extra = daeSafeCast<domExtra>(currentNode->add( COLLADA_ELEMENT_EXTRA ));
        extra->setType("Sequence");
        domTechnique *teq = daeSafeCast<domTechnique>(extra->add( COLLADA_ELEMENT_TECHNIQUE ) );
        teq->setProfile( "OpenSceneGraph" );

        domAny *frameTime = (domAny*)teq->add("FrameTime");
        std::stringstream fw;
        for (unsigned int i = 0; i < node.getNumChildren(); i++) 
        {
            if (i > 0)
            {
                fw << " ";
            }
            fw << node.getTime(i);
        }
        frameTime->setValue(fw.str().c_str());

        domAny *lastFrameTime = (domAny*)teq->add("LastFrameTime");
        lastFrameTime->setValue(toString<double>(node.getLastFrameTime()).c_str());

        // loop mode & interval
        osg::Sequence::LoopMode mode;
        int begin, end;
        node.getInterval(mode, begin, end);
        domAny *loopMode = (domAny*)teq->add("LoopMode");
        loopMode->setValue(toString<osg::Sequence::LoopMode>(mode).c_str());
        domAny *intervalBegin = (domAny*)teq->add("IntervalBegin");
        intervalBegin->setValue(toString<int>(begin).c_str());
        domAny *intervalEnd = (domAny*)teq->add("IntervalEnd");
        intervalEnd->setValue(toString<int>(end).c_str());
        
        // duration
        float speed;
        int nreps;
        node.getDuration(speed, nreps);
        domAny *durationSpeed = (domAny*)teq->add("DurationSpeed");
        durationSpeed->setValue(toString<float>(speed).c_str());
        domAny *durationNReps = (domAny*)teq->add("DurationNReps");
        durationNReps->setValue(toString<int>(nreps).c_str());

        // sequence mode
        domAny *sequenceMode = (domAny*)teq->add("SequenceMode");
        sequenceMode->setValue(toString<osg::Sequence::SequenceMode>(node.getMode()).c_str());
    }

    writeNodeExtra(node);
    
    lastDepth = _nodePath.size();
    
    traverse( node );
}