Exemplo n.º 1
0
OSG::Action::ResultE
initAnimationsEnterFunc(OSG::Node *node)
{
    OSG::Action::ResultE    retVal  = OSG::Action::Continue;
    OSG::GlobalsAttachment *globals = dynamic_cast<OSG::GlobalsAttachment *>(
                                          node->findAttachment(OSG::GlobalsAttachment::getClassType()));

    if(globals == NULL)
        return retVal;

    OSG::GlobalsAttachment::MFElementsType::const_iterator eIt  = globals->getMFElements()->begin();
    OSG::GlobalsAttachment::MFElementsType::const_iterator eEnd = globals->getMFElements()->end  ();

    for(; eIt != eEnd; ++eIt)
    {
        OSG::AnimTemplate *animTmpl = dynamic_cast<OSG::AnimTemplate *>(*eIt);

        if(animTmpl == NULL)
            continue;

        for(OSG::UInt32 i = 0; i < animNames.size(); ++i)
        {
            if(animNames[i] == animTmpl->getName())
            {
                FLOG(("instantiating anim %s\n", animNames[i].c_str()));
                g->anims    [i] = animTmpl->instantiate(node);
                g->anims    [i]->setWeight(0.f);
                g->animState[i] = AnimOff;
            }
        }
    }

    return retVal;
}
void processAnim(OSG::Node *node)
{
    OSG::commitChangesAndClear();

    // register AnimBindAction callbacks -- temporarily done here
    OSG::AnimBindAction::registerEnterDefault(
        OSG::ComponentTransform::getClassType(),
        &OSG::bindEnterDefault                  );
    OSG::AnimBindAction::registerEnterDefault(
        OSG::Transform::getClassType(),
        &OSG::bindEnterDefault                  );


    OSG::GlobalsAttachment *ga = dynamic_cast<OSG::GlobalsAttachment *>(
        node->findAttachment(OSG::GlobalsAttachment::getClassType()));

    if(ga == NULL)
    {
        std::cerr << "WARNING: processAnim: no GlobalsAttachment found"
                  << std::endl;
        return;
    }

    OSG::GlobalsAttachment::MFElementsType::const_iterator eIt  =
        ga->getMFElements()->begin();
    OSG::GlobalsAttachment::MFElementsType::const_iterator eEnd =
        ga->getMFElements()->end  ();

    for(; eIt != eEnd; ++eIt)
    {
        OSG::AnimKeyFrameTemplate *animTmpl =
            dynamic_cast<OSG::AnimKeyFrameTemplate *>(*eIt);

        if(animTmpl == NULL)
            continue;

        std::cout << "instantiating anim template [" << animTmpl->getName()
                  << "] with [" << animTmpl->getMFSources()->size()
                  << "] sources [" << animTmpl->getMFTargetIds()->size() 
                  << "] targetIds" << std::endl;

        AnimInfo ai;
        ai.on   = false;
        ai.anim = animTmpl->instantiate(node);
        ai.anim->setEnabled(false);

        anims.push_back(ai);
    }
}