add re-direct of get mapping for baked assets

This commit is contained in:
Stephen Birarda 2017-08-11 14:26:27 -07:00
parent bef093b8e5
commit db3524a48f
3 changed files with 54 additions and 4 deletions

View file

@ -23,6 +23,7 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QJsonDocument> #include <QtCore/QJsonDocument>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtGui/QImageReader>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <PathUtils.h> #include <PathUtils.h>
@ -264,14 +265,61 @@ void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> me
nodeList->sendPacketList(std::move(replyPacket), *senderNode); nodeList->sendPacketList(std::move(replyPacket), *senderNode);
} }
static const QStringList BAKEABLE_MODEL_EXTENSIONS = { ".fbx" };
static const QString BAKED_MODEL_SIMPLE_NAME = "asset.fbx";
static const QString BAKED_TEXTURE_SIMPLE_NAME = "texture.ktx";
void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) { void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
QString assetPath = message.readString(); QString assetPath = message.readString();
auto it = _fileMappings.find(assetPath); auto it = _fileMappings.find(assetPath);
if (it != _fileMappings.end()) { if (it != _fileMappings.end()) {
auto assetHash = it->toString();
// check if we should re-direct to a baked asset
// first, figure out from the mapping extension what type of file this is
auto assetPathExtension = assetPath.right(assetPath.lastIndexOf('.')).toLower();
QString bakedRootFile;
if (BAKEABLE_MODEL_EXTENSIONS.contains(assetPathExtension)) {
bakedRootFile = BAKED_MODEL_SIMPLE_NAME;
} else if (QImageReader::supportedImageFormats().contains(assetPathExtension.toLocal8Bit())) {
bakedRootFile = BAKED_TEXTURE_SIMPLE_NAME;
}
auto originalAssetHash = it->toString();
QString redirectedAssetHash;
QString bakedAssetPath;
quint8 wasRedirected = false;
if (!bakedRootFile.isEmpty()) {
// we ran into an asset for which we could have a baked version, let's check if it's ready
bakedAssetPath = "/.baked/" + originalAssetHash + "/" + bakedRootFile;
auto bakedIt = _fileMappings.find(bakedAssetPath);
if (bakedIt != _fileMappings.end()) {
// we found a baked version of the requested asset to serve, redirect to that
redirectedAssetHash = bakedIt->toString();
wasRedirected = true;
}
}
replyPacket.writePrimitive(AssetServerError::NoError); replyPacket.writePrimitive(AssetServerError::NoError);
replyPacket.write(QByteArray::fromHex(assetHash.toUtf8()));
if (wasRedirected) {
qDebug() << "Writing re-directed hash for" << originalAssetHash << "to" << redirectedAssetHash;
replyPacket.write(QByteArray::fromHex(redirectedAssetHash.toUtf8()));
// add a flag saying that this mapping request was redirect
replyPacket.writePrimitive(wasRedirected);
// include the re-directed path in case the caller needs to make relative path requests for the baked asset
replyPacket.write(bakedAssetPath.toUtf8());
} else {
replyPacket.write(QByteArray::fromHex(originalAssetHash.toUtf8()));
replyPacket.writePrimitive(wasRedirected);
}
} else { } else {
replyPacket.writePrimitive(AssetServerError::AssetNotFound); replyPacket.writePrimitive(AssetServerError::AssetNotFound);
} }
@ -826,7 +874,6 @@ void AssetServer::handleCompletedBake(AssetHash originalAssetHash, QDir temporar
// setup the mapping for this bake file // setup the mapping for this bake file
auto relativeFilePath = temporaryOutputDir.relativeFilePath(filePath); auto relativeFilePath = temporaryOutputDir.relativeFilePath(filePath);
static const QString BAKED_ASSET_SIMPLE_NAME = "asset.fbx"; static const QString BAKED_ASSET_SIMPLE_NAME = "asset.fbx";
if (relativeFilePath.endsWith(".fbx", Qt::CaseInsensitive)) { if (relativeFilePath.endsWith(".fbx", Qt::CaseInsensitive)) {

View file

@ -42,6 +42,8 @@ PacketVersion versionForPacketType(PacketType packetType) {
return static_cast<PacketVersion>(MessageDataVersion::TextOrBinaryData); return static_cast<PacketVersion>(MessageDataVersion::TextOrBinaryData);
case PacketType::ICEServerHeartbeat: case PacketType::ICEServerHeartbeat:
return 18; // ICE Server Heartbeat signing return 18; // ICE Server Heartbeat signing
case PacketType::AssetMappingOperationReply:
return static_cast<PacketVersion>(AssetServerPacketVersion::RedirectedMappings);
case PacketType::AssetGetInfo: case PacketType::AssetGetInfo:
case PacketType::AssetGet: case PacketType::AssetGet:
case PacketType::AssetUpload: case PacketType::AssetUpload:

View file

@ -266,7 +266,8 @@ enum class EntityQueryPacketVersion: PacketVersion {
enum class AssetServerPacketVersion: PacketVersion { enum class AssetServerPacketVersion: PacketVersion {
VegasCongestionControl = 19, VegasCongestionControl = 19,
RangeRequestSupport RangeRequestSupport,
RedirectedMappings
}; };
enum class AvatarMixerPacketVersion : PacketVersion { enum class AvatarMixerPacketVersion : PacketVersion {