Ejemplo n.º 1
0
void EC_Mesh::OnSkeletonAssetLoaded(AssetPtr asset)
{
    OgreSkeletonAsset *skeletonAsset = dynamic_cast<OgreSkeletonAsset*>(asset.get());
    if (!skeletonAsset)
    {
        LogError("OnSkeletonAssetLoaded: Skeleton asset load finished for asset \"" +
            asset->Name().toStdString() + "\", but downloaded asset was not of type OgreSkeletonAsset!");
        return;
    }

    Ogre::SkeletonPtr skeleton = skeletonAsset->ogreSkeleton;
    if (skeleton.isNull())
    {
        LogError("OnSkeletonAssetLoaded: Skeleton asset load finished for asset \"" +
            asset->Name().toStdString() + "\", but Ogre::Skeleton pointer was null!");
        return;
    }

    if(!entity_)
    {
        LogDebug("Could not set skeleton yet because entity is not yet created");
        return;
    }

    try
    {
        // If old skeleton is same as a new one no need to replace it.
        if (entity_->getSkeleton() && entity_->getSkeleton()->getName() == skeleton->getName())
            return;
        
        entity_->getMesh()->_notifySkeleton(skeleton);
        
//        LogDebug("Set skeleton " + skeleton->getName() + " to mesh " + entity_->getName());
        emit SkeletonChanged(QString::fromStdString(skeleton->getName()));
    }
    catch (...)
    {
        LogError("Exception while setting skeleton to mesh" + entity_->getName());
    }

    // Now we have to recreate the entity to get proper animations etc.
    SetMesh(entity_->getMesh()->getName().c_str(), false);
}
Ejemplo n.º 2
0
Ogre::MeshPtr
loadMesh(const Ogre::String& meshName, const Ogre::String& groupName,
         const Ogre::String& baseResourceName, const Ogre::String& baseGroupName)
{
    // Load the mesh
    Ogre::MeshPtr mesh = loadCorrelativeResource(
        meshName, groupName,
        baseResourceName, baseGroupName,
        Ogre::MeshManager::getSingleton());

    if (mesh.isNull())
    {
        OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
            "Unable to load mesh " + meshName,
            "loadMesh");
    }

    // Try to resolve skeleton resource
    if (mesh->hasSkeleton() && mesh->getSkeleton().isNull())
    {
        // resolve correlative with mesh
        Ogre::SkeletonPtr skeleton = loadCorrelativeResource(
            mesh->getSkeletonName(), groupName,
            mesh->getName(), mesh->getGroup(),
            Ogre::SkeletonManager::getSingleton());

        if (skeleton.isNull())
        {
            // resolve correlative with base resource
            skeleton = loadCorrelativeResource(
                mesh->getSkeletonName(), groupName,
                baseResourceName, baseGroupName,
                Ogre::SkeletonManager::getSingleton());
        }

        if (skeleton.isNull())
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
                "Unable to load skeleton " + mesh->getSkeletonName() +
                " for mesh " + mesh->getName(),
                "loadMesh");
        }

        // Set to the actual name
        mesh->setSkeletonName(skeleton->getName());
    }

    return mesh;
}
Ejemplo n.º 3
0
const std::string& EC_Mesh::GetSkeletonName() const
{
    static std::string empty_name;
    
    if (!entity_)
        return empty_name;
    else
    {
        Ogre::MeshPtr mesh = entity_->getMesh();
        if (!mesh->hasSkeleton())
            return empty_name;
        Ogre::SkeletonPtr skel = mesh->getSkeleton();
        if (skel.isNull())
            return empty_name;
        return skel->getName();
    }
}
Ejemplo n.º 4
0
    //-------------------------------------------------------------------------
    void
    AFile::addTo( Ogre::SkeletonPtr skeleton, const String& name ) const
    {
        if( skeleton->hasAnimation( name) ) return;

        Ogre::Real length( ( m_frames.size() - 1 ) * FRAME_DURATION );
        Ogre::Animation *anim( skeleton->createAnimation(name, length ));
        uint16 track_handle( 0 );
        Ogre::Bone* bone( skeleton->getBone( "root" ) );
        Ogre::NodeAnimationTrack* track;
        track = anim->createNodeTrack( track_handle++, bone );
        Ogre::Real time;
        size_t index( 0 );
        for( FrameList::const_iterator frame( m_frames.begin())
            ;frame != m_frames.end(); ++frame )
        {
            time = (index++) * FRAME_DURATION;
            Ogre::TransformKeyFrame* key_frame( track->createNodeKeyFrame( time ) );
            key_frame->setTranslate( frame->root_translation );
            setFrameRotation( key_frame, frame->root_rotation );
        }
        for( uint32 i(0); i < m_bone_count; ++i )
        {
            if (i + 1 >= skeleton->getNumBones())
            {
                // TODO: Figure out why this happens/fix it
                LOG_ERROR("Bone " + std::to_string(i + 1) + "  is out of bounds " + std::to_string(skeleton->getNumBones()) + " for: " + name + " in: " + skeleton->getName());
            }
            else
            {
                bone = skeleton->getBone(i + 1);
                track = anim->createNodeTrack(track_handle++, bone);
                time = 0;
                for (FrameList::const_iterator frame(m_frames.begin())
                    ; frame != m_frames.end(); ++frame)
                {
                    const Ogre::Vector3& rot(frame->bone_rotations[i]);
                    Ogre::TransformKeyFrame* key_frame(track->createNodeKeyFrame(time));
                    setFrameRotation(key_frame, rot);
                    time += FRAME_DURATION;
                }
            }
        }
    }