Merge pull request #11285 from Atlante45/feat/baking-enabled

Wire "Use baked" checkbox
This commit is contained in:
Stephen Birarda 2017-09-01 16:25:49 -07:00 committed by GitHub
commit 55d44a8c8f
7 changed files with 193 additions and 114 deletions

View file

@ -122,7 +122,7 @@ BakingStatus AssetServer::getAssetStatus(const AssetPath& path, const AssetHash&
auto dotIndex = path.lastIndexOf("."); auto dotIndex = path.lastIndexOf(".");
if (dotIndex == -1) { if (dotIndex == -1) {
return Unrelevant; return Irrelevant;
} }
auto extension = path.mid(dotIndex + 1); auto extension = path.mid(dotIndex + 1);
@ -134,7 +134,7 @@ BakingStatus AssetServer::getAssetStatus(const AssetPath& path, const AssetHash&
} else if (BAKEABLE_TEXTURE_EXTENSIONS.contains(extension.toLocal8Bit()) && hasMetaFile(hash)) { } else if (BAKEABLE_TEXTURE_EXTENSIONS.contains(extension.toLocal8Bit()) && hasMetaFile(hash)) {
bakedFilename = BAKED_TEXTURE_SIMPLE_NAME; bakedFilename = BAKED_TEXTURE_SIMPLE_NAME;
} else { } else {
return Unrelevant; return Irrelevant;
} }
auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + bakedFilename; auto bakedPath = HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" + bakedFilename;
@ -1163,6 +1163,8 @@ void AssetServer::handleCompletedBake(QString originalAssetHash, QString origina
} else { } else {
qWarning() << "Could not complete bake for" << originalAssetHash; qWarning() << "Could not complete bake for" << originalAssetHash;
} }
_pendingBakes.remove(originalAssetHash);
} }
bool AssetServer::createMetaFile(AssetHash originalAssetHash) { bool AssetServer::createMetaFile(AssetHash originalAssetHash) {
@ -1223,10 +1225,17 @@ bool AssetServer::setBakingEnabled(const AssetPathList& paths, bool enabled) {
auto bakedMapping = getBakeMapping(hash, bakedFilename); auto bakedMapping = getBakeMapping(hash, bakedFilename);
if (enabled) { bool currentlyDisabled = (_fileMappings.value(bakedMapping) == hash);
// TODO
} else { if (enabled && currentlyDisabled) {
// TODO QStringList bakedMappings{ bakedMapping };
deleteMappings(bakedMappings);
maybeBake(path, hash);
qDebug() << "Enabled baking for" << path;
} else if (!enabled && !currentlyDisabled) {
removeBakedPathsForDeletedAsset(hash);
setMapping(bakedMapping, hash);
qDebug() << "Disabled baking for" << path;
} }
} }
} }

View file

@ -10,6 +10,7 @@
import QtQuick 2.5 import QtQuick 2.5
import QtQuick.Controls 1.4 import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.2 as OriginalDialogs import QtQuick.Dialogs 1.2 as OriginalDialogs
import Qt.labs.settings 1.0 import Qt.labs.settings 1.0
@ -527,7 +528,6 @@ ScrollingWindow {
headerVisible: true headerVisible: true
sortIndicatorVisible: true sortIndicatorVisible: true
canEdit: true
colorScheme: root.colorScheme colorScheme: root.colorScheme
modifyEl: renameEl modifyEl: renameEl
@ -542,9 +542,131 @@ ScrollingWindow {
id: bakedColumn id: bakedColumn
title: "Use Baked?" title: "Use Baked?"
role: "baked" role: "baked"
width: 140 width: 100
} }
itemDelegate: Loader {
id: itemDelegateLoader
anchors {
left: parent ? parent.left : undefined
leftMargin: (styleData.column === 0 ? (2 + styleData.depth) : 1) * hifi.dimensions.tablePadding
right: parent ? parent.right : undefined
rightMargin: hifi.dimensions.tablePadding
verticalCenter: parent ? parent.verticalCenter : undefined
}
function convertToGlyph(text) {
switch (text) {
case "Not Baked":
return hifi.glyphs.circleSlash;
case "Baked":
return hifi.glyphs.placemark;
case "Error":
return hifi.glyphs.alert;
default:
return "";
}
}
function getComponent() {
if ((styleData.column === 0) && styleData.selected) {
return textFieldComponent;
} else if (convertToGlyph(styleData.value) != "") {
return glyphComponent;
} else {
return labelComponent;
}
}
sourceComponent: getComponent()
Component {
id: labelComponent
FiraSansSemiBold {
text: styleData.value
size: hifi.fontSizes.tableText
color: colorScheme == hifi.colorSchemes.light
? (styleData.selected ? hifi.colors.black : hifi.colors.baseGrayHighlight)
: (styleData.selected ? hifi.colors.black : hifi.colors.lightGrayText)
elide: Text.ElideRight
horizontalAlignment: styleData.column === 1 ? TextInput.AlignHCenter : TextInput.AlignLeft
}
}
Component {
id: glyphComponent
HiFiGlyphs {
text: convertToGlyph(styleData.value)
size: hifi.dimensions.frameIconSize
color: colorScheme == hifi.colorSchemes.light
? (styleData.selected ? hifi.colors.black : hifi.colors.baseGrayHighlight)
: (styleData.selected ? hifi.colors.black : hifi.colors.lightGrayText)
elide: Text.ElideRight
horizontalAlignment: TextInput.AlignHCenter
}
}
Component {
id: textFieldComponent
TextField {
id: textField
readOnly: !activeFocus
text: styleData.value
FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; }
font.family: firaSansSemiBold.name
font.pixelSize: hifi.fontSizes.textFieldInput
height: hifi.dimensions.tableRowHeight
style: TextFieldStyle {
textColor: readOnly
? hifi.colors.black
: (treeView.isLightColorScheme ? hifi.colors.black : hifi.colors.white)
background: Rectangle {
visible: !readOnly
color: treeView.isLightColorScheme ? hifi.colors.white : hifi.colors.black
border.color: hifi.colors.primaryHighlight
border.width: 1
}
selectedTextColor: hifi.colors.black
selectionColor: hifi.colors.primaryHighlight
padding.left: readOnly ? 0 : hifi.dimensions.textPadding
padding.right: readOnly ? 0 : hifi.dimensions.textPadding
}
validator: RegExpValidator {
regExp: /[^/]+/
}
Keys.onPressed: {
if (event.key == Qt.Key_Escape) {
text = styleData.value;
unfocusHelper.forceActiveFocus();
event.accepted = true;
}
}
onAccepted: {
if (acceptableInput && styleData.selected) {
if (!modifyEl(selection.currentIndex, text)) {
text = styleData.value;
}
unfocusHelper.forceActiveFocus();
}
}
onReadOnlyChanged: {
// Have to explicily set keyboardRaised because automatic setting fails because readOnly is true at the time.
keyboardRaised = activeFocus;
}
}
}
}
MouseArea { MouseArea {
propagateComposedEvents: true propagateComposedEvents: true
anchors.fill: parent anchors.fill: parent
@ -604,9 +726,30 @@ ScrollingWindow {
} }
HifiControls.CheckBox { HifiControls.CheckBox {
function isChecked() {
var status = assetProxyModel.data(treeView.selection.currentIndex, 0x105);
var bakingDisabled = (status === "Not Baked" || status === "--");
return selectedItems === 1 && !bakingDisabled;
}
text: "Use baked (optimized) versions" text: "Use baked (optimized) versions"
colorScheme: root.colorScheme colorScheme: root.colorScheme
enabled: selectedItems > 0 enabled: selectedItems === 1 && assetProxyModel.data(treeView.selection.currentIndex, 0x105) !== "--"
checked: isChecked()
onClicked: {
var mappings = [];
for (var i in treeView.selection.selectedIndexes) {
var index = treeView.selection.selectedIndexes[i];
var path = assetProxyModel.data(index, 0x100);
mappings.push(path);
}
print("Setting baking enabled:" + mappings + checked);
Assets.setBakingEnabled(mappings, checked, function() {
reload();
});
checked = Qt.binding(isChecked);
}
} }
} }

View file

@ -19,7 +19,6 @@ TreeView {
id: treeView id: treeView
property var treeModel: ListModel { } property var treeModel: ListModel { }
property var canEdit: false
property bool centerHeaderText: false property bool centerHeaderText: false
property int colorScheme: hifi.colorSchemes.light property int colorScheme: hifi.colorSchemes.light
readonly property bool isLightColorScheme: colorScheme == hifi.colorSchemes.light readonly property bool isLightColorScheme: colorScheme == hifi.colorSchemes.light
@ -198,9 +197,7 @@ TreeView {
: (styleData.alternate ? hifi.colors.tableRowDarkEven : hifi.colors.tableRowDarkOdd) : (styleData.alternate ? hifi.colors.tableRowDarkEven : hifi.colors.tableRowDarkOdd)
} }
itemDelegate: Loader { itemDelegate: FiraSansSemiBold {
id: itemDelegateLoader
anchors { anchors {
left: parent ? parent.left : undefined left: parent ? parent.left : undefined
leftMargin: (2 + styleData.depth) * hifi.dimensions.tablePadding leftMargin: (2 + styleData.depth) * hifi.dimensions.tablePadding
@ -209,24 +206,6 @@ TreeView {
verticalCenter: parent ? parent.verticalCenter : undefined verticalCenter: parent ? parent.verticalCenter : undefined
} }
function getComponent() {
if (treeView.canEdit && styleData.selected) {
return textFieldComponent;
} else {
if (styleData.value.startsWith("HifiGlyphs#")) {
return glyphComponent;
} else {
return labelComponent;
}
}
}
sourceComponent: getComponent()
Component {
id: labelComponent
FiraSansSemiBold {
text: styleData.value text: styleData.value
size: hifi.fontSizes.tableText size: hifi.fontSizes.tableText
color: colorScheme == hifi.colorSchemes.light color: colorScheme == hifi.colorSchemes.light
@ -235,76 +214,6 @@ TreeView {
elide: Text.ElideRight elide: Text.ElideRight
} }
}
Component {
id: glyphComponent
HiFiGlyphs {
text: styleData.value.replace("HifiGlyphs#", "")
size: hifi.fontSizes.tableText
color: colorScheme == hifi.colorSchemes.light
? (styleData.selected ? hifi.colors.black : hifi.colors.baseGrayHighlight)
: (styleData.selected ? hifi.colors.black : hifi.colors.lightGrayText)
elide: Text.ElideRight
}
}
Component {
id: textFieldComponent
TextField {
id: textField
readOnly: !activeFocus
text: styleData.value
FontLoader { id: firaSansSemiBold; source: "../../fonts/FiraSans-SemiBold.ttf"; }
font.family: firaSansSemiBold.name
font.pixelSize: hifi.fontSizes.textFieldInput
height: hifi.dimensions.tableRowHeight
style: TextFieldStyle {
textColor: readOnly
? hifi.colors.black
: (treeView.isLightColorScheme ? hifi.colors.black : hifi.colors.white)
background: Rectangle {
visible: !readOnly
color: treeView.isLightColorScheme ? hifi.colors.white : hifi.colors.black
border.color: hifi.colors.primaryHighlight
border.width: 1
}
selectedTextColor: hifi.colors.black
selectionColor: hifi.colors.primaryHighlight
padding.left: readOnly ? 0 : hifi.dimensions.textPadding
padding.right: readOnly ? 0 : hifi.dimensions.textPadding
}
validator: RegExpValidator {
regExp: /[^/]+/
}
Keys.onPressed: {
if (event.key == Qt.Key_Escape) {
text = styleData.value;
unfocusHelper.forceActiveFocus();
event.accepted = true;
}
}
onAccepted: {
if (acceptableInput && styleData.selected) {
if (!modifyEl(selection.currentIndex, text)) {
text = styleData.value;
}
unfocusHelper.forceActiveFocus();
}
}
onReadOnlyChanged: {
// Have to explicily set keyboardRaised because automatic setting fails because readOnly is true at the time.
keyboardRaised = activeFocus;
}
}
}
}
Item { Item {
id: unfocusHelper id: unfocusHelper

View file

@ -161,7 +161,23 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new
connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable { connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable {
if (callback.isCallable()) { if (callback.isCallable()) {
QJSValueList args { request->getErrorString() }; QJSValueList args{ request->getErrorString() };
callback.call(args);
}
request->deleteLater();
});
request->start();
}
void AssetMappingsScriptingInterface::setBakingEnabled(QStringList paths, bool enabled, QJSValue callback) {
auto assetClient = DependencyManager::get<AssetClient>();
auto request = assetClient->createSetBakingEnabledRequest(paths, enabled);
connect(request, &SetBakingEnabledRequest::finished, this, [this, callback](SetBakingEnabledRequest* request) mutable {
if (callback.isCallable()) {
QJSValueList args{ request->getErrorString() };
callback.call(args); callback.call(args);
} }
@ -220,18 +236,16 @@ void AssetMappingModel::refresh() {
// start index at 1 to avoid empty string from leading slash // start index at 1 to avoid empty string from leading slash
for (int i = 1; i < length; ++i) { for (int i = 1; i < length; ++i) {
fullPath += (i == 1 ? "" : "/") + parts[i]; fullPath += (i == 1 ? "" : "/") + parts[i];
bool isFolder = i < length - 1;
auto it = _pathToItemMap.find(fullPath); auto it = _pathToItemMap.find(fullPath);
if (it == _pathToItemMap.end()) { if (it == _pathToItemMap.end()) {
auto item = new QStandardItem(parts[i]); auto item = new QStandardItem(parts[i]);
bool isFolder = i < length - 1;
auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole); item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
item->setData(isFolder, Qt::UserRole + 1); item->setData(isFolder, Qt::UserRole + 1);
item->setData(parts[i], Qt::UserRole + 2); item->setData(parts[i], Qt::UserRole + 2);
item->setData("atp:" + fullPath, Qt::UserRole + 3); item->setData("atp:" + fullPath, Qt::UserRole + 3);
item->setData(fullPath, Qt::UserRole + 4); item->setData(fullPath, Qt::UserRole + 4);
item->setData(statusString, Qt::UserRole + 5);
if (lastItem) { if (lastItem) {
lastItem->appendRow(item); lastItem->appendRow(item);
@ -243,6 +257,10 @@ void AssetMappingModel::refresh() {
} else { } else {
lastItem = it.value(); lastItem = it.value();
} }
// update status
auto statusString = isFolder ? "--" : bakingStatusToString(mapping.second.status);
lastItem->setData(statusString, Qt::UserRole + 5);
} }
Q_ASSERT(fullPath == path); Q_ASSERT(fullPath == path);

View file

@ -66,10 +66,11 @@ public:
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback = QJSValue()); Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback = QJSValue());
Q_INVOKABLE void getMapping(QString path, QJSValue callback = QJSValue()); Q_INVOKABLE void getMapping(QString path, QJSValue callback = QJSValue());
Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue startedCallback = QJSValue(), QJSValue completedCallback = QJSValue(), bool dropEvent = false); Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue startedCallback = QJSValue(), QJSValue completedCallback = QJSValue(), bool dropEvent = false);
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback); Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback = QJSValue());
Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback = QJSValue()); } Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback = QJSValue()); }
Q_INVOKABLE void getAllMappings(QJSValue callback = QJSValue()); Q_INVOKABLE void getAllMappings(QJSValue callback = QJSValue());
Q_INVOKABLE void renameMapping(QString oldPath, QString newPath, QJSValue callback = QJSValue()); Q_INVOKABLE void renameMapping(QString oldPath, QString newPath, QJSValue callback = QJSValue());
Q_INVOKABLE void setBakingEnabled(QStringList paths, bool enabled, QJSValue callback = QJSValue());
protected: protected:
QSet<AssetRequest*> _pendingRequests; QSet<AssetRequest*> _pendingRequests;

View file

@ -97,7 +97,6 @@ QString bakingStatusToString(BakingStatus status) {
return "Baked"; return "Baked";
case Error: case Error:
return "Error"; return "Error";
case Unrelevant:
default: default:
return "--"; return "--";
} }

View file

@ -55,7 +55,7 @@ enum AssetMappingOperationType : uint8_t {
}; };
enum BakingStatus { enum BakingStatus {
Unrelevant, Irrelevant,
NotBaked, NotBaked,
Pending, Pending,
Baking, Baking,