handle ambient skybox textures for zones in domain bake

This commit is contained in:
Stephen Birarda 2017-04-17 14:57:11 -07:00
parent 7bc69e6eda
commit 25d24c445d
2 changed files with 100 additions and 55 deletions

View file

@ -137,6 +137,8 @@ void DomainBaker::loadLocalFile() {
const QString ENTITY_MODEL_URL_KEY = "modelURL";
const QString ENTITY_SKYBOX_KEY = "skybox";
const QString ENTITY_SKYBOX_URL_KEY = "url";
const QString ENTITY_KEYLIGHT_KEY = "keyLight";
const QString ENTITY_KEYLIGHT_AMBIENT_URL_KEY = "ambientURL";
void DomainBaker::enumerateEntities() {
qDebug() << "Enumerating" << _entities.size() << "entities from domain";
@ -188,10 +190,38 @@ void DomainBaker::enumerateEntities() {
// the model URL to the baked version once the baker is complete
_entitiesNeedingRewrite.insert(modelURL, *it);
}
} else if (entity.contains(ENTITY_SKYBOX_KEY)
&& entity[ENTITY_SKYBOX_KEY].toObject().contains(ENTITY_SKYBOX_URL_KEY)) {
} else {
// We check now to see if we have either a texture for a skybox or a keylight, or both.
if (entity.contains(ENTITY_SKYBOX_KEY)) {
auto skyboxObject = entity[ENTITY_SKYBOX_KEY].toObject();
if (skyboxObject.contains(ENTITY_SKYBOX_URL_KEY)) {
// we have a URL to a skybox, grab it
QUrl skyboxURL { entity[ENTITY_SKYBOX_KEY].toObject()[ENTITY_SKYBOX_URL_KEY].toString() };
QUrl skyboxURL { skyboxObject[ENTITY_SKYBOX_URL_KEY].toString() };
// setup a bake of the skybox
bakeSkybox(skyboxURL, *it);
}
}
if (entity.contains(ENTITY_KEYLIGHT_KEY)) {
auto keyLightObject = entity[ENTITY_KEYLIGHT_KEY].toObject();
if (keyLightObject.contains(ENTITY_KEYLIGHT_AMBIENT_URL_KEY)) {
// we have a URL to a skybox, grab it
QUrl skyboxURL { keyLightObject[ENTITY_KEYLIGHT_AMBIENT_URL_KEY].toString() };
// setup a bake of the skybox
bakeSkybox(skyboxURL, *it);
}
}
}
}
}
// emit progress now to say we're just starting
emit bakeProgress(0, _totalNumberOfSubBakes);
}
void DomainBaker::bakeSkybox(QUrl skyboxURL, QJsonValueRef entity) {
auto skyboxFileName = skyboxURL.fileName();
@ -229,14 +259,8 @@ void DomainBaker::enumerateEntities() {
// add this QJsonValueRef to our multi hash so that it can re-write the skybox URL
// to the baked version once the baker is complete
_entitiesNeedingRewrite.insert(skyboxURL, *it);
_entitiesNeedingRewrite.insert(skyboxURL, entity);
}
}
}
}
// emit progress now to say we're just starting
emit bakeProgress(0, _totalNumberOfSubBakes);
}
void DomainBaker::handleFinishedModelBaker() {
@ -281,7 +305,7 @@ void DomainBaker::handleFinishedModelBaker() {
QUrl oldAnimationURL { animationObject[ENTITIY_ANIMATION_URL_KEY].toString() };
// check if its stripped down version matches our stripped down model URL
if (oldAnimationURL.matches(oldModelURL, QUrl::RemoveUserInfo | QUrl::RemoveQuery | QUrl::RemoveFragment)) {
if (oldAnimationURL.matches(oldModelURL, QUrl::RemoveQuery | QUrl::RemoveFragment)) {
// the animation URL matched the old model URL, so make the animation URL point to the baked FBX
// with its original query and fragment
auto newAnimationURL = _destinationPath.resolved(baker->getBakedFBXRelativePath());
@ -338,25 +362,23 @@ void DomainBaker::handleFinishedSkyboxBaker() {
auto skyboxObject = entity[ENTITY_SKYBOX_KEY].toObject();
if (skyboxObject.contains(ENTITY_SKYBOX_URL_KEY)) {
// grab the old skybox URL
QUrl oldSkyboxURL { skyboxObject[ENTITY_SKYBOX_URL_KEY].toString() };
// the animation URL matched the old model URL, so make the animation URL point to the baked FBX
// with its original query and fragment
auto bakedSkyboxFileName = QFileInfo(baker->getDestinationFilePath()).fileName();
auto newSkyboxURL = _destinationPath.resolved(bakedSkyboxFileName);
newSkyboxURL.setQuery(oldSkyboxURL.query());
newSkyboxURL.setFragment(oldSkyboxURL.fragment());
newSkyboxURL.setUserInfo(oldSkyboxURL.userInfo());
skyboxObject[ENTITY_SKYBOX_URL_KEY] = newSkyboxURL.toString();
// replace the skybox object referenced by the entity object
if (rewriteSkyboxURL(skyboxObject[ENTITY_SKYBOX_URL_KEY], baker)) {
// we re-wrote the URL, replace the skybox object referenced by the entity object
entity[ENTITY_SKYBOX_KEY] = skyboxObject;
}
}
}
if (entity.contains(ENTITY_KEYLIGHT_KEY)) {
auto ambientObject = entity[ENTITY_KEYLIGHT_KEY].toObject();
if (ambientObject.contains(ENTITY_KEYLIGHT_AMBIENT_URL_KEY)) {
if (rewriteSkyboxURL(ambientObject[ENTITY_KEYLIGHT_AMBIENT_URL_KEY], baker)) {
// we re-wrote the URL, replace the ambient object referenced by the entity object
entity[ENTITY_KEYLIGHT_KEY] = ambientObject;
}
}
}
// replace our temp object with the value referenced by our QJsonValueRef
entityValue = entity;
@ -379,7 +401,27 @@ void DomainBaker::handleFinishedSkyboxBaker() {
// check if this was the last model we needed to re-write and if we are done now
checkIfRewritingComplete();
}
}
bool DomainBaker::rewriteSkyboxURL(QJsonValueRef urlValue, TextureBaker* baker) {
// grab the old skybox URL
QUrl oldSkyboxURL { urlValue.toString() };
if (oldSkyboxURL.matches(baker->getTextureURL(), QUrl::RemoveQuery | QUrl::RemoveFragment)) {
// change the URL to point to the baked texture with its original query and fragment
auto bakedSkyboxFileName = QFileInfo(baker->getDestinationFilePath()).fileName();
auto newSkyboxURL = _destinationPath.resolved(bakedSkyboxFileName);
newSkyboxURL.setQuery(oldSkyboxURL.query());
newSkyboxURL.setFragment(oldSkyboxURL.fragment());
newSkyboxURL.setUserInfo(oldSkyboxURL.userInfo());
urlValue = newSkyboxURL.toString();
return true;
} else {
return false;
}
}
void DomainBaker::checkIfRewritingComplete() {

View file

@ -46,6 +46,9 @@ private:
void checkIfRewritingComplete();
void writeNewEntitiesFile();
void bakeSkybox(QUrl skyboxURL, QJsonValueRef entity);
bool rewriteSkyboxURL(QJsonValueRef urlValue, TextureBaker* baker);
QUrl _localEntitiesFileURL;
QString _domainName;
QString _baseOutputPath;