mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 08:23:04 +02:00
Fix existing baked assets not being recognized
This commit is contained in:
parent
6ac8cdecd1
commit
6f3155db32
2 changed files with 72 additions and 24 deletions
|
@ -100,7 +100,7 @@ QString bakedFilenameForAssetType(BakedAssetType type) {
|
||||||
BakeVersion currentBakeVersionForAssetType(BakedAssetType type) {
|
BakeVersion currentBakeVersionForAssetType(BakedAssetType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Model:
|
case Model:
|
||||||
return (BakeVersion)ModelBakeVersion::BetterModelBaking;
|
return (BakeVersion)ModelBakeVersion::Initial;
|
||||||
case Texture:
|
case Texture:
|
||||||
return (BakeVersion)TextureBakeVersion::Initial;
|
return (BakeVersion)TextureBakeVersion::Initial;
|
||||||
case Script:
|
case Script:
|
||||||
|
@ -110,12 +110,40 @@ BakeVersion currentBakeVersionForAssetType(BakedAssetType type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString toSlug(BakedAssetType type) {
|
struct BakedTypeInfo {
|
||||||
switch (type) {
|
BakedAssetType type;
|
||||||
Model: return "model";
|
const char* slug;
|
||||||
Texture: return "texture";
|
BakeVersion currentVersion;
|
||||||
|
const char* bakedName;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr std::array<BakedTypeInfo, BakedAssetType::NUM_ASSET_TYPES> BAKED_TYPE_INFO { {
|
||||||
|
{
|
||||||
|
Model,
|
||||||
|
"model",
|
||||||
|
(BakeVersion)ModelBakeVersion::Initial,
|
||||||
|
"asset.fbx",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Texture,
|
||||||
|
"texture",
|
||||||
|
(BakeVersion)TextureBakeVersion::Initial,
|
||||||
|
"texture.ktx",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Script,
|
||||||
|
"script",
|
||||||
|
(BakeVersion)ScriptBakeVersion::FixEmptyScripts,
|
||||||
|
"asset.js",
|
||||||
}
|
}
|
||||||
}
|
}};
|
||||||
|
|
||||||
|
static_assert(BAKED_TYPE_INFO[BakedAssetType::Model].type == BakedAssetType::Model,
|
||||||
|
"Model should be in correct index");
|
||||||
|
static_assert(BAKED_TYPE_INFO[BakedAssetType::Texture].type == BakedAssetType::Texture,
|
||||||
|
"Texture should be in correct index");
|
||||||
|
static_assert(BAKED_TYPE_INFO[BakedAssetType::Script].type == BakedAssetType::Script,
|
||||||
|
"Script should be in correct index");
|
||||||
|
|
||||||
const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server";
|
const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server";
|
||||||
|
|
||||||
|
@ -251,6 +279,10 @@ bool AssetServer::needsToBeBaked(const AssetUtils::AssetPath& path, const AssetU
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meta.bakeVersion < currentVersion) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString bakedFilename = bakedFilenameForAssetType(type);
|
QString bakedFilename = bakedFilenameForAssetType(type);
|
||||||
auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename;
|
auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename;
|
||||||
auto bakedPath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename;
|
auto bakedPath = AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER + assetHash + "/" + bakedFilename;
|
||||||
|
@ -706,10 +738,20 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, NLPacketLi
|
||||||
auto query = QUrlQuery(url.query());
|
auto query = QUrlQuery(url.query());
|
||||||
bool isSkybox = query.hasQueryItem("skybox");
|
bool isSkybox = query.hasQueryItem("skybox");
|
||||||
if (isSkybox) {
|
if (isSkybox) {
|
||||||
writeMetaFile(originalAssetHash);
|
bool loaded;
|
||||||
|
AssetMeta meta;
|
||||||
|
std::tie(loaded, meta) = readMetaFile(originalAssetHash);
|
||||||
|
|
||||||
|
if (!loaded) {
|
||||||
|
AssetMeta needsBakingMeta;
|
||||||
|
needsBakingMeta.bakeVersion = NEEDS_BAKING_BAKE_VERSION;
|
||||||
|
|
||||||
|
writeMetaFile(originalAssetHash, needsBakingMeta);
|
||||||
if (!bakingDisabled) {
|
if (!bakingDisabled) {
|
||||||
maybeBake(assetPath, originalAssetHash);
|
maybeBake(assetPath, originalAssetHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1335,9 +1377,12 @@ void AssetServer::handleFailedBake(QString originalAssetHash, QString assetPath,
|
||||||
|
|
||||||
std::tie(loaded, meta) = readMetaFile(originalAssetHash);
|
std::tie(loaded, meta) = readMetaFile(originalAssetHash);
|
||||||
|
|
||||||
|
auto type = assetTypeForFilename(assetPath);
|
||||||
|
auto currentTypeVersion = currentBakeVersionForAssetType(type);
|
||||||
|
|
||||||
meta.failedLastBake = true;
|
meta.failedLastBake = true;
|
||||||
meta.lastBakeErrors = errors;
|
meta.lastBakeErrors = errors;
|
||||||
meta.bakeVersion = (BakeVersion)CURRENT_MODEL_BAKE_VERSION;
|
meta.bakeVersion = currentTypeVersion;
|
||||||
|
|
||||||
writeMetaFile(originalAssetHash, meta);
|
writeMetaFile(originalAssetHash, meta);
|
||||||
|
|
||||||
|
@ -1427,18 +1472,20 @@ void AssetServer::handleCompletedBake(QString originalAssetHash, QString origina
|
||||||
qWarning() << "Failed to remove temporary directory:" << bakedTempOutputDir;
|
qWarning() << "Failed to remove temporary directory:" << bakedTempOutputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!errorCompletingBake) {
|
auto type = assetTypeForFilename(originalAssetPath);
|
||||||
// create the meta file to store which version of the baking process we just completed
|
auto currentTypeVersion = currentBakeVersionForAssetType(type);
|
||||||
writeMetaFile(originalAssetHash);
|
|
||||||
} else {
|
|
||||||
qWarning() << "Could not complete bake for" << originalAssetHash;
|
|
||||||
AssetMeta meta;
|
AssetMeta meta;
|
||||||
meta.failedLastBake = true;
|
meta.bakeVersion = currentTypeVersion;
|
||||||
|
meta.failedLastBake = errorCompletingBake;
|
||||||
|
|
||||||
|
if (errorCompletingBake) {
|
||||||
|
qWarning() << "Could not complete bake for" << originalAssetHash;
|
||||||
meta.lastBakeErrors = errorReason;
|
meta.lastBakeErrors = errorReason;
|
||||||
meta.bakeVersion = (BakeVersion)ModelBakeVersion::BetterModelBaking;
|
|
||||||
writeMetaFile(originalAssetHash, meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeMetaFile(originalAssetHash, meta);
|
||||||
|
|
||||||
_pendingBakes.remove(originalAssetHash);
|
_pendingBakes.remove(originalAssetHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1475,7 +1522,7 @@ std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetUtils::AssetHash hash)
|
||||||
if (error.error == QJsonParseError::NoError && doc.isObject()) {
|
if (error.error == QJsonParseError::NoError && doc.isObject()) {
|
||||||
auto root = doc.object();
|
auto root = doc.object();
|
||||||
|
|
||||||
auto bakeVersion = root[BAKE_VERSION_KEY].toInt(-1);
|
auto bakeVersion = root[BAKE_VERSION_KEY].toInt(INITIAL_BAKE_VERSION);
|
||||||
auto failedLastBake = root[FAILED_LAST_BAKE_KEY];
|
auto failedLastBake = root[FAILED_LAST_BAKE_KEY];
|
||||||
auto lastBakeErrors = root[LAST_BAKE_ERRORS_KEY];
|
auto lastBakeErrors = root[LAST_BAKE_ERRORS_KEY];
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ namespace std {
|
||||||
}
|
}
|
||||||
|
|
||||||
using BakeVersion = int;
|
using BakeVersion = int;
|
||||||
|
static const BakeVersion INITIAL_BAKE_VERSION = 0;
|
||||||
|
static const BakeVersion NEEDS_BAKING_BAKE_VERSION = -1;
|
||||||
|
|
||||||
enum BakedAssetType : int {
|
enum BakedAssetType : int {
|
||||||
Model = 0,
|
Model = 0,
|
||||||
|
@ -44,17 +46,16 @@ enum BakedAssetType : int {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ModelBakeVersion : BakeVersion {
|
enum class ModelBakeVersion : BakeVersion {
|
||||||
Initial = 0,
|
Initial = INITIAL_BAKE_VERSION
|
||||||
BetterModelBaking,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class TextureBakeVersion : BakeVersion {
|
enum class TextureBakeVersion : BakeVersion {
|
||||||
Initial = 0,
|
Initial = INITIAL_BAKE_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ScriptBakeVersion : BakeVersion {
|
enum class ScriptBakeVersion : BakeVersion {
|
||||||
Initial = 0,
|
Initial = INITIAL_BAKE_VERSION,
|
||||||
FixEmptyScripts = 1
|
FixEmptyScripts,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AssetMeta {
|
struct AssetMeta {
|
||||||
|
|
Loading…
Reference in a new issue