Example #1
0
void EC_MediaPlayer::OnMediaLoaded(AssetPtr asset)
{
    pendingMediaDownload_ = false;

    // Double check that same source finished as we have in the attribute.
    if (asset->Name() != getsourceRef().ref.trimmed())
        return;

    // Load media from local file
    QString diskSource = asset->DiskSource();
    if (!diskSource.isEmpty())
    {
        // Feed native separators for VLC
        if (!mediaPlayer_->LoadMedia(QDir::toNativeSeparators(diskSource)))
            LogError("EC_MediaPlayer: Source not supported: " + asset->Name());
        else
        {
            LogInfo("EC_MediaPlayer: Loaded source media after download '" + asset->Name() + "'");
            emit MediaDownloaded(true, asset->Name());
            mediaPlayer_->ForceUpdateImage();
        }
    }
    else
        LogError("EC_MediaPlayer: Downloaded media '" + asset->Name() + "' disk source is empty! Broken/disabled asset cache?");
}
Example #2
0
void EC_Mesh::OnMaterialAssetLoaded(AssetPtr asset)
{
    OgreMaterialAsset *ogreMaterial = dynamic_cast<OgreMaterialAsset*>(asset.get());
    if (!ogreMaterial)
    {
        LogError("OnMaterialAssetLoaded: Material asset load finished for asset \"" +
            asset->Name().toStdString() + "\", but downloaded asset was not of type OgreMaterialAsset!");
        return;
    }

    Ogre::MaterialPtr material = ogreMaterial->ogreMaterial;
    bool assetUsed = false;

    AssetReferenceList materialList = meshMaterial.Get();
    for(int i = 0; i < materialList.Size(); ++i)
        if (materialList[i].ref == ogreMaterial->Name() ||
            framework_->Asset()->LookupAssetRefToStorage(materialList[i].ref) == ogreMaterial->Name()) ///<///\todo The design of whether the LookupAssetRefToStorage should occur here, or internal to Asset API needs to be revisited.
        {
            SetMaterial(i, ogreMaterial->Name());
            assetUsed = true;
        }

    if (!assetUsed)
    {
        LogWarning("OnMaterialAssetLoaded: Trying to apply material \"" + ogreMaterial->Name().toStdString() + "\" to mesh " +
            meshRef.Get().ref.toStdString() + ", but no submesh refers to the given material! The references are: ");
        for(int i = 0; i < materialList.Size(); ++i)
            LogWarning(QString::number(i).toStdString() + ": " + materialList[i].ref.toStdString());
    }
}
Example #3
0
void EC_Mesh::OnMeshAssetLoaded(AssetPtr asset)
{
    OgreMeshAsset *mesh = dynamic_cast<OgreMeshAsset*>(asset.get());
    if (!mesh)
    {
        LogError("OnMeshAssetLoaded: Mesh asset load finished for asset \"" + asset->Name().toStdString() + "\", but downloaded asset was not of type OgreMeshAsset!");
        return;
    }

    QString ogreMeshName = mesh->Name();
    if (mesh)
    {
        if (mesh->ogreMesh.get())
        {
            ogreMeshName = QString::fromStdString(mesh->ogreMesh->getName()).trimmed();

            // Do not reload if all of the following are met
            // 1. Ogre::Entity and Ogre::Mesh are valid (aka this is not the first load for this EC_Mesh) 
            // 2. Mesh name is same (aka asset reference with ogre sanitations)
            // 3. Content hash has not changed (aka data has not changed)
            if (entity_ && entity_->getMesh().get())
            {
                QString currentMeshName = QString::fromStdString(entity_->getMesh()->getName()).trimmed();
                if (currentMeshName == ogreMeshName && mesh->ContentHashChanged() == false)
                    return;
            }
        }
        else
            LogError("OnMeshAssetLoaded: Mesh asset load finished for asset \"" + asset->Name().toStdString() + "\", but Ogre::Mesh pointer was null!");
    }

    SetMesh(ogreMeshName);

    // Force a re-application of the skeleton on this mesh. ///\todo This path should be re-evaluated to see if we have potential performance issues here. -jj.
    if (skeletonAsset->Asset())
        OnSkeletonAssetLoaded(skeletonAsset->Asset());

    // Apply pending materials, these were tried to be applied before the mesh was loaded
    if (!pendingMaterialApplies.empty())
    {
        for(int idx = 0; idx < pendingMaterialApplies.size(); ++idx)
            SetMaterial(idx, pendingMaterialApplies[idx]);
        pendingMaterialApplies.clear();
    }
}
void AssetRefListener::OnAssetCreated(AssetPtr assetData)
{
    if (assetData.Get() && !currentWaitingRef.Empty() && currentWaitingRef == assetData->Name())
    {
        /// @todo Remove this logic once a EC_Material + EC_Mesh behaves correctly without failed requests, see generated:// logic in HandleAssetRefChange.
        /** Log the same message as before for non generated:// refs. This is good to do
            because AssetAPI has now said the request failed, so user might be confused when it still works. */
        if (!currentWaitingRef.ToLower().StartsWith("generated://"))
            LogInfo("AssetRefListener: Asset \"" + assetData->Name() + "\" was created, applying after it loads.");

        // The asset we are waiting for has been created, hook to the IAsset::Loaded signal.
        currentWaitingRef = "";
        asset = assetData;
        assetData->Loaded.Connect(this, &AssetRefListener::OnAssetLoaded);
        if (myAssetAPI)
            myAssetAPI->AssetCreated.Disconnect(this, &AssetRefListener::OnAssetCreated);
    }
}
Example #5
0
void OgreScriptEditor::SetScriptAsset(const AssetPtr &scriptAsset)
{
    asset = scriptAsset;
    assert(asset.lock());
    AssetPtr assetPtr = asset.lock();
    if (!assetPtr)
        LogError("OgreScriptEditor: null asset given.");
    if (assetPtr->Type() != "OgreMaterial" && assetPtr->Type() != "OgreParticle")
        LogWarning("Created OgreScriptEditor for non-supported asset type " + assetPtr->Type() + ".");

    lineEditName->setText((assetPtr?assetPtr->Name():QString()));
    setWindowTitle(tr("OGRE Script Editor:") + (assetPtr?assetPtr->Name():QString()));

    if (assetPtr && !assetPtr->IsLoaded())
    {
        AssetTransferPtr transfer = framework->Asset()->RequestAsset(assetPtr->Name(), assetPtr->Type(), true);
        connect(transfer.get(), SIGNAL(Succeeded(AssetPtr)), this, SLOT(OnAssetTransferSucceeded(AssetPtr)));
        connect(transfer.get(), SIGNAL(Failed(IAssetTransfer *, QString)), SLOT(OnAssetTransferFailed(IAssetTransfer *, QString)));
    }
Example #6
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);
}
void AssetRefListListener::OnAssetLoaded(AssetPtr asset)
{
    if (!asset)
        return;

    bool signaled = false;
    String completedRef = asset->Name();
    for(uint i = 0; i < current_.Size(); ++i)
    {
        const AssetReference &ref = current_[i];
        if (ref.ref.Compare(completedRef, false) == 0)
        {
            // Don't break/return. Same asset might be in multiple indexes!
            Loaded.Emit(i, asset);
            signaled = true;
        }
    }
    if (!signaled)
        LogWarning("AssetRefListListener: Failed to signal completion of " + completedRef + ". The asset ref is unknown to the local state.");
}
Example #8
0
void RigidBody::OnCollisionMeshAssetLoaded(AssetPtr asset)
{
    IMeshAsset* meshAsset = dynamic_cast<IMeshAsset*>(asset.Get());
    if (!meshAsset)
        LogError("RigidBody::OnCollisionMeshAssetLoaded: Mesh asset load finished for asset \"" +
            asset->Name() + "\", but asset pointer was null!");

    if (shapeType.Get() == TriMesh)
    {
        impl->triangleMesh = impl->owner->GetTriangleMeshFromMeshAsset(meshAsset);
        CreateCollisionShape();
    }
    else if (shapeType.Get() == ConvexHull)
    {
        impl->convexHullSet = impl->owner->GetConvexHullSetFromMeshAsset(meshAsset);
        CreateCollisionShape();
    }

    impl->cachedShapeType = shapeType.Get();
    impl->cachedSize = size.Get();
}
Example #9
0
void EC_Hydrax::ConfigLoadSucceeded(AssetPtr asset)
{
    PROFILE(EC_Hydrax_ConfigLoadSucceeded);
    // If we haven't yet initialized, do a full init.
    if (!impl || !impl->hydrax || !impl->module)
        Create();

    if (!impl || !impl->hydrax || !impl->module)
    {
        LogError("EC_Hydrax: Could not apply Hydrax config \"" + asset->Name() + "\", Hydrax could not be initialized!");
        return;
    }

    std::vector<u8> rawData;
    asset->SerializeTo(rawData);
    QString configData = QString::fromAscii((const char*)&rawData[0], (int)rawData.size());

    if (configData.isEmpty())
    {
        LogInfo("EC_Hydrax: Downloaded config is empty!");
        return;
    }

    try
    {
        // Update the noise module
        if (configData.contains("noise=fft", Qt::CaseInsensitive))
        {
            /// \note Using the FFT noise plugin seems to crash somewhere after we leave this function.
            /// FFT looks better so would be nice to investigate further!
            if (impl->module->getNoise()->getName() != "FFT")
                impl->module->setNoise(new Hydrax::Noise::FFT());
        }
        else if (configData.contains("noise=perlin", Qt::CaseInsensitive))
        {
            if (impl->module->getNoise()->getName() != "Perlin")
                impl->module->setNoise(new Hydrax::Noise::Perlin());
        }
        else
        {
            LogError("EC_Hydrax: Unknown noise param in loaded config, acceptable = FFT/Perlin.");
            SAFE_DELETE(impl);
            return;
        }

        // Load config from the asset data string.
        impl->hydrax->remove();
        impl->hydrax->loadCfgString(configData.toStdString());
        
        // Override the shader mode specified in the config - OpenGL should always use GLSL, D3D HLSL.
        // (Cg is never used, for compatibility, since it requires an extra install and some Linux systems don't always have it enabled)
        if (QString(Ogre::Root::getSingleton().getRenderSystem()->getName().c_str()).contains("OpenGL"))
            impl->hydrax->setShaderMode(Hydrax::MaterialManager::SM_GLSL);
        else
            impl->hydrax->setShaderMode(Hydrax::MaterialManager::SM_HLSL);
        impl->hydrax->create();

        // The position attribute is always authoritative from the component attribute.
        if (visible.Get())
            impl->hydrax->setPosition(position.Get());
    }
    catch (const Ogre::Exception &e)
    {
        LogError(std::string("EC_Hydrax: Ogre threw exception while loading new config: ") + e.what());
        if (impl && impl->hydrax)
            impl->hydrax->remove();
        SAFE_DELETE(impl);
    }
}
Example #10
0
QString AssetCache::StoreAsset(AssetPtr asset)
{
    std::vector<u8> data;
    asset->SerializeTo(data);
    return StoreAsset(&data[0], data.size(), asset->Name());
}