Я пытался заставить SkyX работать некоторое время, но не смог. Вот мой код:
//THESE ARE GLOBAL
SkyX::BasicController* skyBasicController = NULL;
SkyX::SkyX* mSkyX = NULL;
Ogre::Camera* camera;
...
Ogre::SceneManager *sceneManager = ogreMain.getRoot()->createSceneManager(
Ogre::ST_GENERIC, "MainSceneManager");
Ogre::SceneNode *rootSceneNode = sceneManager->getRootSceneNode();
Ogre::ResourceGroupManager& resGrpMgr =
Ogre::ResourceGroupManager::getSingleton();
Ogre::String terrainResGrpName = "Terrain";
resGrpMgr.createResourceGroup(terrainResGrpName);
resGrpMgr.addResourceLocation(".\\Media\\Terrain\\programs", "FileSystem",
terrainResGrpName, 0);
resGrpMgr.addResourceLocation(".\\Media\\Terrain\\scripts", "FileSystem",
terrainResGrpName, 0);
resGrpMgr.addResourceLocation(".\\Media\\Terrain\\textures", "FileSystem",
terrainResGrpName, 0);
// The function 'initialiseResourceGroup' parses scripts if any in the locations.
resGrpMgr.initialiseResourceGroup(terrainResGrpName);
// Files that can be loaded are loaded.
resGrpMgr.loadResourceGroup(terrainResGrpName);
Ogre::String skyResGrpName = "SkyX";
resGrpMgr.createResourceGroup(skyResGrpName);
resGrpMgr.addResourceLocation(".\\Media\\SkyX", "FileSystem", skyResGrpName,
0);
// The function 'initialiseResourceGroup' parses scripts if any in the locations.
resGrpMgr.initialiseResourceGroup(skyResGrpName);
// Files that can be loaded are loaded.
resGrpMgr.loadResourceGroup(skyResGrpName);
ogreMain.getWindow()->setActive(true);
ogreMain.getWindow()->setAutoUpdated(false);
sceneManager->setAmbientLight(Ogre::ColourValue(.6, .6, .6));
sceneManager->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
sceneManager->setShadowColour(ColourValue(0, 0, 0));
camera = sceneManager->createCamera();
Ogre::SceneNode *camera_node = player_node->createChildSceneNode();
camera_node->attachObject(camera);
float viewport_width = 1.0f;
float viewport_height = 1.0f;
float viewport_left = (1.0f - viewport_width) * 0.5f;
float viewport_top = (1.0f - viewport_height) * 0.5f;
unsigned short lMainViewportZOrder = 100;
Ogre::Viewport *vp = ogreMain.getWindow()->addViewport(camera,
lMainViewportZOrder, viewport_left, viewport_top, viewport_width,
viewport_height);
vp->setAutoUpdated(true);
//vp->setBackgroundColour(Ogre::ColourValue(0.2f, 0.2f, 0.2f));
float ratio = float(vp->getActualWidth()) / float(vp->getActualHeight());
camera->setAspectRatio(ratio);
camera->setNearClipDistance(1.5f);
camera->setFarClipDistance(50000);
camera->setPosition(0, 6, 26);
camera->setDirection(0, -1, -6.5f);
...
skyBasicController = new SkyX::BasicController();
mSkyX = new SkyX::SkyX(sceneManager, skyBasicController);
mSkyX->create();
mSkyX->getVCloudsManager()->getVClouds()->setDistanceFallingParams(
Ogre::Vector2(2, -1));
ogreMain.getRoot()->addFrameListener(mSkyX);
ogreMain.getWindow()->addListener(mSkyX);
setPreset(mPresets[3]);
ogreMain.getRoot()->clearEventTimes();
... //some var declarations, then main loop
//BELOW HERE IS TAKEN FROM 2ND DEMO
struct SkyXSettings
{
/** Constructor
@remarks Skydome + vol. clouds + lightning settings
*/
SkyXSettings(const Ogre::Vector3 t, const Ogre::Real& tm, const Ogre::Real& mp, const SkyX::AtmosphereManager::Options& atmOpt,
const bool& lc, const bool& vc, const Ogre::Real& vcws, const bool& vcauto, const Ogre::Radian& vcwd,
const Ogre::Vector3& vcac, const Ogre::Vector4& vclr, const Ogre::Vector4& vcaf, const Ogre::Vector2& vcw,
const bool& vcl, const Ogre::Real& vclat, const Ogre::Vector3& vclc, const Ogre::Real& vcltm)
: time(t), timeMultiplier(tm), moonPhase(mp), atmosphereOpt(atmOpt), layeredClouds(lc), volumetricClouds(vc), vcWindSpeed(vcws)
, vcAutoupdate(vcauto), vcWindDir(vcwd), vcAmbientColor(vcac), vcLightResponse(vclr), vcAmbientFactors(vcaf), vcWheater(vcw)
, vcLightnings(vcl), vcLightningsAT(vclat), vcLightningsColor(vclc), vcLightningsTM(vcltm)
{}
/** Constructor
@remarks Skydome + vol. clouds
*/
SkyXSettings(const Ogre::Vector3 t, const Ogre::Real& tm, const Ogre::Real& mp, const SkyX::AtmosphereManager::Options& atmOpt,
const bool& lc, const bool& vc, const Ogre::Real& vcws, const bool& vcauto, const Ogre::Radian& vcwd,
const Ogre::Vector3& vcac, const Ogre::Vector4& vclr, const Ogre::Vector4& vcaf, const Ogre::Vector2& vcw)
: time(t), timeMultiplier(tm), moonPhase(mp), atmosphereOpt(atmOpt), layeredClouds(lc), volumetricClouds(vc), vcWindSpeed(vcws)
, vcAutoupdate(vcauto), vcWindDir(vcwd), vcAmbientColor(vcac), vcLightResponse(vclr), vcAmbientFactors(vcaf), vcWheater(vcw), vcLightnings(false)
{}
/** Constructor
@remarks Skydome settings
*/
SkyXSettings(const Ogre::Vector3 t, const Ogre::Real& tm, const Ogre::Real& mp, const SkyX::AtmosphereManager::Options& atmOpt, const bool& lc)
: time(t), timeMultiplier(tm), moonPhase(mp), atmosphereOpt(atmOpt), layeredClouds(lc), volumetricClouds(false), vcLightnings(false)
{}
/// Time
Ogre::Vector3 time;
/// Time multiplier
Ogre::Real timeMultiplier;
/// Moon phase
Ogre::Real moonPhase;
/// Atmosphere options
SkyX::AtmosphereManager::Options atmosphereOpt;
/// Layered clouds?
bool layeredClouds;
/// Volumetric clouds?
bool volumetricClouds;
/// VClouds wind speed
Ogre::Real vcWindSpeed;
/// VClouds autoupdate
bool vcAutoupdate;
/// VClouds wind direction
Ogre::Radian vcWindDir;
/// VClouds ambient color
Ogre::Vector3 vcAmbientColor;
/// VClouds light response
Ogre::Vector4 vcLightResponse;
/// VClouds ambient factors
Ogre::Vector4 vcAmbientFactors;
/// VClouds wheater
Ogre::Vector2 vcWheater;
/// VClouds lightnings?
bool vcLightnings;
/// VClouds lightnings average aparition time
Ogre::Real vcLightningsAT;
/// VClouds lightnings color
Ogre::Vector3 vcLightningsColor;
/// VClouds lightnings time multiplier
Ogre::Real vcLightningsTM;
};
/** Demo presets
@remarks The best way of determinate each parameter value is by using a real-time editor.
These presets have been quickly designed using the Paradise Editor, which is a commercial solution.
At the time I'm writting these lines, SkyX 0.1 is supported by Ogitor. Hope that the Ogitor team will
support soon SkyX 0.3, this way you all are going to be able to quickly create cool SkyX configurations.
*/
SkyXSettings mPresets[] = {
// Sunset
SkyXSettings(Ogre::Vector3(8.85f, 7.5f, 20.5f), -0.08f, 0, SkyX::AtmosphereManager::Options(9.77501f, 10.2963f, 0.01f, 0.0022f, 0.000675f, 30, Ogre::Vector3(0.57f, 0.52f, 0.44f), -0.991f, 3, 4), false, true, 300, false, Ogre::Radian(270), Ogre::Vector3(0.63f,0.63f,0.7f), Ogre::Vector4(0.35, 0.2, 0.92, 0.1), Ogre::Vector4(0.4, 0.7, 0, 0), Ogre::Vector2(0.8,1)),
// Clear
SkyXSettings(Ogre::Vector3(17.16f, 7.5f, 20.5f), 0, 0, SkyX::AtmosphereManager::Options(9.77501f, 10.2963f, 0.01f, 0.0017f, 0.000675f, 30, Ogre::Vector3(0.57f, 0.54f, 0.44f), -0.991f, 2.5f, 4), false),
// Thunderstorm 1
SkyXSettings(Ogre::Vector3(12.23, 7.5f, 20.5f), 0, 0, SkyX::AtmosphereManager::Options(9.77501f, 10.2963f, 0.01f, 0.00545f, 0.000375f, 30, Ogre::Vector3(0.55f, 0.54f, 0.52f), -0.991f, 1, 4), false, true, 300, false, Ogre::Radian(0), Ogre::Vector3(0.63f,0.63f,0.7f), Ogre::Vector4(0.25, 0.4, 0.5, 0.1), Ogre::Vector4(0.45, 0.3, 0.6, 0.1), Ogre::Vector2(1,1), true, 0.5, Ogre::Vector3(1,0.976,0.92), 2),
// Thunderstorm 2
SkyXSettings(Ogre::Vector3(10.23, 7.5f, 20.5f), 0, 0, SkyX::AtmosphereManager::Options(9.77501f, 10.2963f, 0.01f, 0.00545f, 0.000375f, 30, Ogre::Vector3(0.55f, 0.54f, 0.52f), -0.991f, 0.5, 4), false, true, 300, false, Ogre::Radian(0), Ogre::Vector3(0.63f,0.63f,0.7f), Ogre::Vector4(0, 0.02, 0.34, 0.24), Ogre::Vector4(0.29, 0.3, 0.6, 1), Ogre::Vector2(1,1), true, 0.5, Ogre::Vector3(0.95,1,1), 2),
// Desert
SkyXSettings(Ogre::Vector3(7.59f, 7.5f, 20.5f), 0, -0.8f, SkyX::AtmosphereManager::Options(9.77501f, 10.2963f, 0.01f, 0.0072f, 0.000925f, 30, Ogre::Vector3(0.71f, 0.59f, 0.53f), -0.997f, 2.5f, 1), true),
// Night
SkyXSettings(Ogre::Vector3(21.5f, 7.5, 20.5), 0.03, -0.25, SkyX::AtmosphereManager::Options(), true)
};
void setPreset(const SkyXSettings& preset)
{
mSkyX->setTimeMultiplier(preset.timeMultiplier);
mBasicController->setTime(preset.time);
mBasicController->setMoonPhase(preset.moonPhase);
mSkyX->getAtmosphereManager()->setOptions(preset.atmosphereOpt);
// Layered clouds
if (preset.layeredClouds)
{
// Create layer cloud
if (mSkyX->getCloudsManager()->getCloudLayers().empty())
{
mSkyX->getCloudsManager()->add(SkyX::CloudLayer::Options(/* Default options */));
}
}
else
{
// Remove layer cloud
if (!mSkyX->getCloudsManager()->getCloudLayers().empty())
{
mSkyX->getCloudsManager()->removeAll();
}
}
mSkyX->getVCloudsManager()->setWindSpeed(preset.vcWindSpeed);
mSkyX->getVCloudsManager()->setAutoupdate(preset.vcAutoupdate);
SkyX::VClouds::VClouds* vclouds = mSkyX->getVCloudsManager()->getVClouds();
vclouds->setWindDirection(preset.vcWindDir);
vclouds->setAmbientColor(preset.vcAmbientColor);
vclouds->setLightResponse(preset.vcLightResponse);
vclouds->setAmbientFactors(preset.vcAmbientFactors);
vclouds->setWheater(preset.vcWheater.x, preset.vcWheater.y, false);
if (preset.volumetricClouds)
{
// Create VClouds
if (!mSkyX->getVCloudsManager()->isCreated())
{
// SkyX::MeshManager::getSkydomeRadius(...) works for both finite and infinite(=0) camera far clip distances
mSkyX->getVCloudsManager()->create(mSkyX->getMeshManager()->getSkydomeRadius(mRenderingCamera));
}
}
else
{
// Remove VClouds
if (mSkyX->getVCloudsManager()->isCreated())
{
mSkyX->getVCloudsManager()->remove();
}
}
vclouds->getLightningManager()->setEnabled(preset.vcLightnings);
vclouds->getLightningManager()->setAverageLightningApparitionTime(preset.vcLightningsAT);
vclouds->getLightningManager()->setLightningColor(preset.vcLightningsColor);
vclouds->getLightningManager()->setLightningTimeMultiplier(preset.vcLightningsTM);
//mTextArea->setCaption(buildInfoStr());
// Reset camera position/orientation
//mRenderingCamera->setPosition(0,0,0);
//mRenderingCamera->setDirection(0,0,1);
mSkyX->update(0);
}
Я не использую FrameworkApplication или любой другой фреймворк. Я написал свой маленький класс с моими потребностями.
Я вижу только молнии, и они кажутся слишком близкими по сравнению с демонстрациями. Кроме того, происхождение всех молний постоянно находится наверху камеры, двигаясь вместе с ней.
У меня есть только несколько коробок и камера, прикрепленная к одной из них в моей сцене.
Я скомпилировал SkyX 0.3.1 как отдельную DLL, с теми же библиотеками boost и ogre (с приложением, все confed как debug), что и debug conf ‘set.
Вывод отладки с упоминанием SkyX выглядит следующим образом:
Creating resource group Terrain
Added resource location '.\Media\Terrain\programs' of type 'FileSystem' to resource group 'Terrain'
Added resource location '.\Media\Terrain\scripts' of type 'FileSystem' to resource group 'Terrain'
Added resource location '.\Media\Terrain\textures' of type 'FileSystem' to resource group 'Terrain'
Initialising resource group Terrain
Parsing scripts for resource group Terrain
Parsing script Terrain.material
Finished parsing scripts for resource group Terrain
Creating resources for group Terrain
All done
Loading resource group 'Terrain' - Resources: 1 World Geometry: 1
Texture: TerrainAmbientMap.jpg: Loading 1 faces(PF_L8,512x512x1) Internal format is PF_L8,512x512x1.
Texture: TerrainTex0.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) Internal format is PF_X8R8G8B8,512x512x1.
Texture: TerrainTex1.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) Internal format is PF_X8R8G8B8,512x512x1.
Finished loading resource group Terrain
Creating resource group SkyX
Added resource location '.\Media\SkyX' of type 'FileSystem' to resource group 'SkyX'
Initialising resource group SkyX
Parsing scripts for resource group SkyX
Parsing script SkyX.material
Finished parsing scripts for resource group SkyX
Creating resources for group SkyX
All done
Loading resource group 'SkyX' - Resources: 1 World Geometry: 1
Texture: Noise.jpg: Loading 1 faces(PF_R8G8B8,1024x1024x1) Internal format is PF_X8R8G8B8,1024x1024x1.
Texture: SkyX_Starfield.png: Loading 1 faces(PF_A8R8G8B8,512x512x1) Internal format is PF_A8R8G8B8,512x512x1.
Texture: SkyX_Moon.png: Loading 1 faces(PF_A8R8G8B8,512x512x1) Internal format is PF_A8R8G8B8,512x512x1.
Texture: SkyX_MoonHalo.png: Loading 1 faces(PF_A8R8G8B8,512x256x1) Internal format is PF_A8R8G8B8,512x256x1.
Finished loading resource group SkyX
...
Can't assign material _NULL_ to SubEntity of SkyXMeshEnt because this Material does not exist. Have you forgotten to define it in a .material script?
[SkyX] VClouds warning: unregistered camera registered, manual unregistering is needed before camera destruction
Благодарю.
Простое удаление следующей строки решило проблему. Видимо тени не работают с SkyX.
sceneManager->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
Вы можете использовать эту строку после инициализации SkyX, но я не знаю, работает она или нет.
Других решений пока нет …