コード例 #1
0
ファイル: SkyxEditor.cpp プロジェクト: jacmoe/ogitor
//---------------------------------------------------------------------------------
bool CSkyxEditor::load(bool async)
{
    if(mLoaded->get())
        return true;

    Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr();
    Ogre::String value = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/SkyX/";
    mngr->addResourceLocation(value, "Ofs", "SkyX");
    mngr->initialiseResourceGroup("SkyX");

	// Create SkyX
    mBasicController = new SkyX::BasicController(true);
    mHandle = new SkyX::SkyX(mOgitorsRoot->GetSceneManager(), mBasicController);
	mHandle->create();

    mHandle->getVCloudsManager()->getVClouds()->registerCamera(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera());

    mHandle->getVCloudsManager()->getVClouds()->setDistanceFallingParams(Ogre::Vector2(2, -1));

    _restoreState();

    registerForUpdates();

    mLoaded->set(true);
    return true;
}
コード例 #2
0
//--------------------------------------------------------------------------------------------------
CCaelumEditor::CCaelumEditor(CBaseEditorFactory *factory) : CBaseEditor(factory),
    _mUpdateCounter(0)
{
    mHandle = 0;
    mSceneManager = 0;
    
    mName->init("CaelumSky");

    Ogre::ResourceGroupManager *resmngr = Ogre::ResourceGroupManager::getSingletonPtr();
    Ogre::String value = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + mOgitorsRoot->GetProjectOptions()->CaelumDirectory + "/";
    resmngr->addResourceLocation(value,"Ofs","Caelum");
    resmngr->initialiseResourceGroup("Caelum");
}
コード例 #3
0
//---------------------------------------------------------------------------------
bool CSkyxEditor::load(bool async)
{
    if(mLoaded->get())
        return true;

    Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr();
    Ogre::String value = OgitorsUtils::QualifyPath(mOgitorsRoot->GetProjectOptions()->ProjectDir + "/SkyX");
    mngr->addResourceLocation(value,"FileSystem","SkyX");
    mngr->initialiseResourceGroup("SkyX");

	// Create SkyX
    mHandle = new SkyX::SkyX(mOgitorsRoot->GetSceneManager(), mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera());
	mHandle->create();

    mHandle->getVCloudsManager()->create();

    _restoreState();

    registerForUpdates();

    mLoaded->set(true);
    return true;
}
コード例 #4
0
//-----------------------------------------------------------------------------------------
bool CTerrainGroupEditor::load(bool async)
{
    if(mLoaded->get())
        return true;

    if(!getParent()->load())
        return false;

    Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr();
    Ogre::String terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory;
    terrainDir = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + terrainDir + "/";

    mngr->addResourceLocation(terrainDir + "textures/normalheight", "Ofs", "TerrainGroupNormalHeight");
    mngr->initialiseResourceGroup("TerrainGroupNormalHeight");

    mngr->addResourceLocation(terrainDir + "textures/diffusespecular", "Ofs", "TerrainGroupDiffuseSpecular");
    mngr->initialiseResourceGroup("TerrainGroupDiffuseSpecular");

    mngr->addResourceLocation(terrainDir + "plants", "Ofs", "TerrainGroupPlants");
    mngr->initialiseResourceGroup("TerrainGroupPlants");

    OgitorsRoot::getSingletonPtr()->PrepareTerrainResources();
    OgitorsRoot::getSingletonPtr()->ReloadUserResources();

    mDecalFrustum = OGRE_NEW Ogre::Frustum();
    mDecalNode = getSceneManager()->getRootSceneNode()->createChildSceneNode("OgitorTerrainDecalNode");
    mDecalNode->setPosition(99999, -99999, 99999);
    mDecalNode->attachObject(mDecalFrustum);
    mDecalFrustum->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    mDecalNode->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X));
    mDecalFrustum->setFOVy(Ogre::Degree(45));
    mDecalFrustum->setNearClipDistance(10);
    mDecalFrustum->setOrthoWindow(10, 10);
    mDecalFrustum->setVisible(false);
    mDecalTexture = Ogre::TextureManager::getSingletonPtr()->createManual("OgitorDecalTexture", "TerrainResources", 
        Ogre::TEX_TYPE_2D, 256, 256, 1, 1, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY, this);

    mBrushData = OGRE_ALLOC_T(float, BRUSH_DATA_SIZE * BRUSH_DATA_SIZE, Ogre::MEMCATEGORY_GEOMETRY);

    mTerrainGlobalOptions->setMaxPixelError(mMaxPixelError->get());
    mTerrainGlobalOptions->setCompositeMapSize(mCompositeMapTextureSize->get());
    mTerrainGlobalOptions->setCompositeMapDistance(mCompositeMapDistance->get());
    mTerrainGlobalOptions->setLightMapSize(mLightMapTextureSize->get());
    mTerrainGlobalOptions->setLayerBlendMapSize(mBlendMapTextureSize->get());
    mTerrainGlobalOptions->setUseVertexCompressionWhenAvailable(false);
    mTerrainGlobalOptions->setSkirtSize(mSkirtSize->get());
    mTerrainGlobalOptions->setUseRayBoxDistanceCalculation(mUseRayBoxDistanceCalculation->get());

    if(mMaterialGeneratorType->get() == 1)
    {
        Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorC(this, mDecalFrustum));
        mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr);
        mMaxLayersAllowed = 10;
    }
    else
    {
        Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorB(this, mDecalFrustum));
        mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr);
        mMaxLayersAllowed = 6;
    }

    CSceneManagerEditor *mSceneMgr = static_cast<CSceneManagerEditor*>(mOgitorsRoot->GetSceneManagerEditor());

    if(mSceneMgr->getShadowsEnabled())
    {
        if(mMaterialGeneratorType->get() == 1)
        {
            Ogre::TerrainMaterialGeneratorC::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorC::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile());
            matProfile->setReceiveDynamicShadowsEnabled(true);
            matProfile->setReceiveDynamicShadowsLowLod(false);
            matProfile->setReceiveDynamicShadowsDepth(true);
            matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get()));
        }
        else
        {
            Ogre::TerrainMaterialGeneratorB::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorB::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile());
            matProfile->setReceiveDynamicShadowsEnabled(true);
            matProfile->setReceiveDynamicShadowsLowLod(false);
            matProfile->setReceiveDynamicShadowsDepth(true);
            matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get()));
        }
    }

    CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::enabled", CTerrainGroupEditor, onShadowsChange, mShadowsConnection[0]);
    CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::technique", CTerrainGroupEditor, onShadowsTechniqueChange, mShadowsConnection[1]);

    mHandle = OGRE_NEW Ogre::TerrainGroup(mOgitorsRoot->GetSceneManager(), Ogre::Terrain::ALIGN_X_Z, mMapSize->get(), mWorldSize->get());
    mHandle->setOrigin(Ogre::Vector3::ZERO);
    mHandle->setResourceGroup("TerrainResources");
    mHandle->setFilenameConvention(mPageNamePrefix->get(), "ogt");
    StaticGroupPtr = mHandle;

    mPGHandle = new PagedGeometry(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera(), mPGPageSize->get());
    mPGHandle->addDetailLevel<GrassPage>(mPGDetailDistance->get());

    //Create a GrassLoader object
    mGrassLoaderHandle = new GrassLoader(mPGHandle);
    mGrassLoaderHandle->setVisibilityFlags(1 << mLayer->get());

    //Assign the "grassLoader" to be used to load geometry for the PagedGrass instance
    mPGHandle->setPageLoader(mGrassLoaderHandle);

    //Supply a height function to GrassLoader so it can calculate grass Y values
    mGrassLoaderHandle->setHeightFunction(OgitorTerrainGroupHeightFunction);

    Ogre::Vector3 vDir;
    Ogre::ColourValue cDiffuse;
    Ogre::SceneManager::MovableObjectIterator mit = mOgitorsRoot->GetSceneManager()->getMovableObjectIterator("Light");
    while(mit.hasMoreElements())
    {
        Ogre::Light *l = static_cast<Ogre::Light*>(mit.getNext());
        if(l->getType() == Ogre::Light::LT_DIRECTIONAL && l->getCastShadows())
        {
            vDir = l->getDerivedDirection();
            cDiffuse = l->getDiffuseColour();
            break;
        }
    }

    mTerrainGlobalOptions->setLightMapDirection(vDir);
    mTerrainGlobalOptions->setCompositeMapAmbient(mOgitorsRoot->GetSceneManager()->getAmbientLight());
    mTerrainGlobalOptions->setCompositeMapDiffuse(cDiffuse);

    terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory + "/terrain/";

    OFS::FileList TGAList = mOgitorsRoot->GetProjectFile()->listFiles(terrainDir.c_str(), OFS::OFS_FILE);

    for(unsigned int t = 0; t < TGAList.size(); t++)
    {
        int pos = TGAList[t].name.find("_density.tga");
        if(pos > 0)
        {
            Ogre::Image _img;
            Ogre::String sLoc = terrainDir + TGAList[t].name;

            // Block to ensure streams are freed when exiting the block
            {
                OFS::OFSHANDLE *iHandle = new OFS::OFSHANDLE();
                mOgitorsRoot->GetProjectFile()->openFile( *iHandle, sLoc.c_str() );
                Ogre::DataStreamPtr img_stream = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mOgitorsRoot->GetProjectFile(), iHandle));
                _img.load(img_stream);
            }

            Ogre::String nLoc = terrainDir + TGAList[t].name.substr(0, pos);
            nLoc += "_density.png";

            OgitorsUtils::SaveImageOfs( _img, nLoc );
            mOgitorsRoot->GetProjectFile()->deleteFile( sLoc.c_str() );
        }
    }

    registerForUpdates();

    mLoaded->set(true);
    return true;
}