Ejemplo n.º 1
0
void OgreMeshAsset::operationCompleted(Ogre::BackgroundProcessTicket ticket, const Ogre::BackgroundProcessResult &result)
{
    if (ticket != loadTicket_)
        return;

    if (!result.error)
    {
        /*! \todo Verify if we need to do
            - ogreMesh->setAutoBuildEdgeLists(false);
            - ogreMesh->buildTangentVectors(...);
            - smesh->generateExtremes(n);
            for non-manual created meshes via thread loading.
        */

        ogreMesh = Ogre::MeshManager::getSingleton().getByName(OgreRenderer::SanitateAssetIdForOgre(Name().toStdString()), 
                                                               OgreRenderer::OgreRenderingModule::CACHE_RESOURCE_GROUP);
        if (!ogreMesh.isNull())
        {        
            try
            {
                SetDefaultMaterial();
                assetAPI->OnTransferAssetLoadCompleted(Name(), ASSET_LOAD_SUCCESFULL);
                return;
            }
            catch (Ogre::Exception &e)
            {
                LogError("Failed to set default materials to " + this->Name().toStdString() + ": " + std::string(e.what()));
            }
        }
        else   
            LogError("Ogre::Mesh was null after threaded loading: " + this->Name().toStdString());
    }
    else
        LogError("Ogre failed to do threaded loading: " + result.message);

    Unload();
    assetAPI->OnTransferAssetLoadCompleted(Name(), ASSET_LOAD_FAILED);
}
Ejemplo n.º 2
0
bool OgreMeshAsset::GenerateMeshData()
{
    if (ogreMesh.isNull())
        return false;
    /* NOTE: only the last error handler here returns false - first are ignored.
       This is to keep the behaviour identical to the original version which had these checks inside 
       DeserializeFromData - see https://github.com/realXtend/naali/blob/1806ea04057d447263dbd7cf66d5731c36f4d4a3/src/Core/OgreRenderingModule/OgreMeshAsset.cpp#L89
    */
    
    // Generate tangents to mesh
    try
    {
        unsigned short src, dest;
        ///\bug Crashes if called for a mesh that has null or zero vertices in the vertex buffer, or null or zero indices in the index buffer.
        if (!ogreMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
            ogreMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
    }
    catch(const Ogre::Exception &e)
    {
        QString what(e.what());
        // "Cannot locate an appropriate 2D texture coordinate set" is benign, see OgreLogListener::messageLogged
        const bool hideBenignOgreMessages = ( assetAPI->GetFramework()->HasCommandLineParameter("--hideBenignOgreMessages") ||
            assetAPI->GetFramework()->HasCommandLineParameter("--hide_benign_ogre_messages")); /**< @todo Remove support for the deprecated underscore version at some point. */
        if (!hideBenignOgreMessages || (hideBenignOgreMessages && !what.contains("Cannot locate an appropriate 2D texture coordinate set")))
            LogError("OgreMeshAsset::GenerateMeshData: Failed to build tangents for mesh " + this->Name() + ": " + what);
    }

    // Generate extremity points to submeshes, 1 should be enough
    try
    {
        for(unsigned short i = 0; i < ogreMesh->getNumSubMeshes(); ++i)
        {
            Ogre::SubMesh *smesh = ogreMesh->getSubMesh(i);
            if (smesh)
                smesh->generateExtremes(1);
        }
    }
    catch(const Ogre::Exception &e)
    {
        LogError("OgreMeshAsset::GenerateMeshData: Failed to generate extremity points to submeshes for mesh " + this->Name() + ": " + QString(e.what()));
    }

    try
    {
        // Assign default materials that won't complain
        if (!IsAssimpFileType())
            SetDefaultMaterial();
        // Set asset references the mesh has
        //ResetReferences();
    }
    catch(const Ogre::Exception &e)
    {
        LogError("OgreMeshAsset::GenerateMeshData: Failed to set default materials to " + this->Name() + ": " + QString(e.what()));
        Unload();
        return false;
    }

    //internal_name_ = AssetAPI::SanitateAssetRef(id_);
    //LogDebug("Ogre mesh " + this->Name().toStdString() + " created");

    return true;
}
Ejemplo n.º 3
0
    int Engine::Init(int width, int height, int colordepth, bool fullscreen)
    {
       //initialize Direct3D
        this->p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
        if (this->p_d3d == NULL) {
            return 0;
        }
    
        //get system desktop color depth
        D3DDISPLAYMODE dm;
        this->p_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);
    
        //set configuration options for Direct3D
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = (!fullscreen);
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
        d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
        d3dpp.BackBufferFormat = dm.Format;
        d3dpp.BackBufferCount = 1;
        d3dpp.BackBufferWidth = width;
        d3dpp.BackBufferHeight = height;
        d3dpp.hDeviceWindow = p_windowHandle;
    
        //create Direct3D device
        this->p_d3d->CreateDevice(
            D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            this->p_windowHandle,
            D3DCREATE_HARDWARE_VERTEXPROCESSING,
            &d3dpp,
            &this->p_device);
    
        if (this->p_device == NULL) return 0;
    
        //clear the backbuffer to black
        this->ClearScene(D3DCOLOR_XRGB(0,0,0));
    
        //create pointer to the back buffer
        this->p_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &this->p_backbuffer);
    
        //use ambient lighting and z-buffering
        this->p_device->SetRenderState(D3DRS_ZENABLE, TRUE);
        this->p_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
        this->p_device->SetRenderState(D3DRS_LIGHTING, true);
        this->SetAmbient(this->p_ambientColor);
    
        //initialize 2D renderer
        HRESULT result = D3DXCreateSprite(this->p_device, &this->p_sprite_handler);
        if (result != D3D_OK) return 0;
    
        
        //call game initialization extern function
        if (!game_init(this->getWindowHandle()))
            return 0;
    
        //set a default material
        SetDefaultMaterial();

        //initialize DirectInput
        p_input = CSingleton<Input>::GetInstance();
		p_input->Init(this->getWindowHandle());
    
        return 1;
    }
Ejemplo n.º 4
0
AssetLoadState OgreMeshAsset::DeserializeFromData(const u8 *data_, size_t numBytes)
{
    PROFILE(OgreMeshAsset_LoadFromFileInMemory);
    assert(data_);
    if (!data_)
        return ASSET_LOAD_FAILED;
    
    // Force an unload of this data first.
    Unload();

    if (OGRE_THREAD_SUPPORT != 0)
    {
        // We can only do threaded loading from disk, and not any disk location but only from asset cache.
        // local:// refs will return empty string here and those will fall back to the non-threaded loading.
        // Do not change this to do DiskCache() as that directory for local:// refs will not be a known resource location for ogre.
        QString cacheDiskSource = assetAPI->GetAssetCache()->GetDiskSource(QUrl(Name()));
        if (!cacheDiskSource.isEmpty())
        {
            QFileInfo fileInfo(cacheDiskSource);
            std::string sanitatedAssetRef = fileInfo.fileName().toStdString(); 
            loadTicket_ = Ogre::ResourceBackgroundQueue::getSingleton().load(Ogre::MeshManager::getSingleton().getResourceType(),
                                                                             sanitatedAssetRef, OgreRenderer::OgreRenderingModule::CACHE_RESOURCE_GROUP,
                                                                             false, 0, 0, this);
            return ASSET_LOAD_PROCESSING;
        }
    }

    if (ogreMesh.isNull())
    {   
        ogreMesh = Ogre::MeshManager::getSingleton().createManual(
            OgreRenderer::SanitateAssetIdForOgre(this->Name().toStdString()), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        if (ogreMesh.isNull())
        {
            LogError("Failed to create mesh " + Name().toStdString());
            return ASSET_LOAD_FAILED; 
        }
        ogreMesh->setAutoBuildEdgeLists(false);
    }

    std::vector<u8> tempData(data_, data_ + numBytes);
#include "DisableMemoryLeakCheck.h"
    Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream((void*)&tempData[0], numBytes, false));
#include "EnableMemoryLeakCheck.h"
    Ogre::MeshSerializer serializer;
    serializer.importMesh(stream, ogreMesh.getPointer()); // Note: importMesh *adds* submeshes to an existing mesh. It doesn't replace old ones.
    
    // Generate tangents to mesh
    try
    {
        unsigned short src, dest;
        ///\bug Crashes if called for a mesh that has null or zero vertices in the vertex buffer, or null or zero indices in the index buffer.
        if (!ogreMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
            ogreMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
    }
    catch (...) {}
    
    // Generate extremity points to submeshes, 1 should be enough
    try
    {
        for(uint i = 0; i < ogreMesh->getNumSubMeshes(); ++i)
        {
            Ogre::SubMesh *smesh = ogreMesh->getSubMesh(i);
            if (smesh)
                smesh->generateExtremes(1);
        }
    }
    catch (...) {}
        
    try
    {
        // Assign default materials that won't complain
        SetDefaultMaterial();
        // Set asset references the mesh has
        //ResetReferences();
    }
    catch (Ogre::Exception &e)
    {
        LogError("Failed to create mesh " + this->Name().toStdString() + ": " + std::string(e.what()));
        Unload();
        return ASSET_LOAD_FAILED;
    }

    //internal_name_ = SanitateAssetIdForOgre(id_);
    
    LogDebug("Ogre mesh " + this->Name().toStdString() + " created");
    return ASSET_LOAD_SUCCESFULL;
}