Fix for skybox not always loading

This commit is contained in:
Atlante45 2016-01-11 18:58:46 -08:00
parent 0008b1a055
commit 5e41421f9d
2 changed files with 89 additions and 78 deletions

View file

@ -24,7 +24,6 @@
#include <SceneScriptingInterface.h> #include <SceneScriptingInterface.h>
#include <ScriptEngine.h> #include <ScriptEngine.h>
#include <procedural/ProceduralSkybox.h> #include <procedural/ProceduralSkybox.h>
#include <TextureCache.h>
#include "EntityTreeRenderer.h" #include "EntityTreeRenderer.h"
@ -142,7 +141,7 @@ void EntityTreeRenderer::update() {
// even if we haven't changed positions, if we previously attempted to set the skybox, but // even if we haven't changed positions, if we previously attempted to set the skybox, but
// have a pending download of the skybox texture, then we should attempt to reapply to // have a pending download of the skybox texture, then we should attempt to reapply to
// get the correct texture. // get the correct texture.
if (_pendingSkyboxTextureDownload) { if (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) {
applyZonePropertiesToScene(_bestZone); applyZonePropertiesToScene(_bestZone);
} }
@ -255,13 +254,14 @@ void EntityTreeRenderer::forceRecheckEntities() {
void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) { void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) {
QSharedPointer<SceneScriptingInterface> scene = DependencyManager::get<SceneScriptingInterface>(); auto scene = DependencyManager::get<SceneScriptingInterface>();
auto sceneStage = scene->getStage(); auto sceneStage = scene->getStage();
auto skyStage = scene->getSkyStage();
auto sceneKeyLight = sceneStage->getKeyLight(); auto sceneKeyLight = sceneStage->getKeyLight();
auto sceneLocation = sceneStage->getLocation(); auto sceneLocation = sceneStage->getLocation();
auto sceneTime = sceneStage->getTime(); auto sceneTime = sceneStage->getTime();
auto backgroundMode = BACKGROUND_MODE_INHERIT; // Default
if (zone) {
if (!_hasPreviousZone) { if (!_hasPreviousZone) {
_previousKeyLightColor = sceneKeyLight->getColor(); _previousKeyLightColor = sceneKeyLight->getColor();
_previousKeyLightIntensity = sceneKeyLight->getIntensity(); _previousKeyLightIntensity = sceneKeyLight->getIntensity();
@ -275,6 +275,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_previousStageDay = sceneTime->getDay(); _previousStageDay = sceneTime->getDay();
_hasPreviousZone = true; _hasPreviousZone = true;
} }
if (zone) {
backgroundMode = zone->getBackgroundMode();
sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor())); sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor()));
sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity()); sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity());
sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity()); sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity());
@ -284,8 +288,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
zone->getStageProperties().getAltitude()); zone->getStageProperties().getAltitude());
sceneTime->setHour(zone->getStageProperties().calculateHour()); sceneTime->setHour(zone->getStageProperties().calculateHour());
sceneTime->setDay(zone->getStageProperties().calculateDay()); sceneTime->setDay(zone->getStageProperties().calculateDay());
}
if (zone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) { switch (backgroundMode) {
case BACKGROUND_MODE_ATMOSPHERE: {
EnvironmentData data = zone->getEnvironmentData(); EnvironmentData data = zone->getEnvironmentData();
glm::vec3 keyLightDirection = sceneKeyLight->getDirection(); glm::vec3 keyLightDirection = sceneKeyLight->getDirection();
glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f; glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f;
@ -302,19 +308,18 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
data.setSunBrightness(sunBrightness); data.setSunBrightness(sunBrightness);
_viewState->overrideEnvironmentData(data); _viewState->overrideEnvironmentData(data);
scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME);
_pendingSkyboxTextureDownload = false; _pendingSkyboxTexture = false;
_skyboxTexture.clear();
} else { break;
_viewState->endOverrideEnvironmentData(); }
auto stage = scene->getSkyStage(); case BACKGROUND_MODE_SKYBOX: {
if (zone->getBackgroundMode() == BACKGROUND_MODE_SKYBOX) { auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(stage->getSkybox());
skybox->setColor(zone->getSkyboxProperties().getColorVec3()); skybox->setColor(zone->getSkyboxProperties().getColorVec3());
static QString userData; static QString userData;
if (userData != zone->getUserData()) { if (userData != zone->getUserData()) {
userData = zone->getUserData(); userData = zone->getUserData();
ProceduralPointer procedural(new Procedural(userData)); auto procedural = std::make_shared<Procedural>(userData);
if (procedural->_enabled) { if (procedural->_enabled) {
skybox->setProcedural(procedural); skybox->setProcedural(procedural);
} else { } else {
@ -323,26 +328,26 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
} }
if (zone->getSkyboxProperties().getURL().isEmpty()) { if (zone->getSkyboxProperties().getURL().isEmpty()) {
skybox->setCubemap(gpu::TexturePointer()); skybox->setCubemap(gpu::TexturePointer());
_pendingSkyboxTextureDownload = false; _pendingSkyboxTexture = false;
_skyboxTexture.clear();
} else { } else {
// Update the Texture of the Skybox with the one pointed by this zone // Update the Texture of the Skybox with the one pointed by this zone
auto cubeMap = DependencyManager::get<TextureCache>()->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); auto textureCache = DependencyManager::get<TextureCache>();
_skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE);
if (cubeMap->getGPUTexture()) { if (_skyboxTexture->getGPUTexture()) {
skybox->setCubemap(cubeMap->getGPUTexture()); skybox->setCubemap(_skyboxTexture->getGPUTexture());
_pendingSkyboxTextureDownload = false; _pendingSkyboxTexture = false;
} else { } else {
_pendingSkyboxTextureDownload = true; _pendingSkyboxTexture = true;
} }
} }
stage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
} else { _viewState->endOverrideEnvironmentData();
stage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
_pendingSkyboxTextureDownload = false; break;
} }
} case BACKGROUND_MODE_INHERIT:
} else {
_pendingSkyboxTextureDownload = false;
if (_hasPreviousZone) { if (_hasPreviousZone) {
sceneKeyLight->setColor(_previousKeyLightColor); sceneKeyLight->setColor(_previousKeyLightColor);
sceneKeyLight->setIntensity(_previousKeyLightIntensity); sceneKeyLight->setIntensity(_previousKeyLightIntensity);
@ -356,7 +361,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_hasPreviousZone = false; _hasPreviousZone = false;
} }
_viewState->endOverrideEnvironmentData(); _viewState->endOverrideEnvironmentData();
scene->getSkyStage()->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application atmosphere through
_pendingSkyboxTexture = false;
_skyboxTexture.clear();
break;
} }
} }

View file

@ -15,12 +15,13 @@
#include <QSet> #include <QSet>
#include <QStack> #include <QStack>
#include <EntityTree.h> #include <AbstractAudioInterface.h>
#include <EntityScriptingInterface.h> // for RayToEntityIntersectionResult #include <EntityScriptingInterface.h> // for RayToEntityIntersectionResult
#include <EntityTree.h>
#include <MouseEvent.h> #include <MouseEvent.h>
#include <OctreeRenderer.h> #include <OctreeRenderer.h>
#include <ScriptCache.h> #include <ScriptCache.h>
#include <AbstractAudioInterface.h> #include <TextureCache.h>
class AbstractScriptingServicesInterface; class AbstractScriptingServicesInterface;
class AbstractViewStateInterface; class AbstractViewStateInterface;
@ -142,9 +143,11 @@ private:
void forceRecheckEntities(); void forceRecheckEntities();
glm::vec3 _lastAvatarPosition; glm::vec3 _lastAvatarPosition;
bool _pendingSkyboxTextureDownload = false;
QVector<EntityItemID> _currentEntitiesInside; QVector<EntityItemID> _currentEntitiesInside;
bool _pendingSkyboxTexture = false;
NetworkTexturePointer _skyboxTexture;
bool _wantScripts; bool _wantScripts;
ScriptEngine* _entitiesScriptEngine; ScriptEngine* _entitiesScriptEngine;