From 3943fe2861511ff26014f66fa0f15c918b4ea844 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 10 Dec 2018 21:29:03 +0100 Subject: [PATCH] avatar packager initial --- .../resources/qml/hifi/AvatarPackager.qml | 54 +++++++++++++++++++ interface/src/Application.cpp | 3 ++ interface/src/Menu.cpp | 7 +++ interface/src/Menu.h | 1 + interface/src/avatar/AvatarPackager.cpp | 44 +++++++++++++++ interface/src/avatar/AvatarPackager.h | 35 ++++++++++++ interface/src/avatar/AvatarProject.cpp | 27 ++++++++++ interface/src/avatar/AvatarProject.h | 45 ++++++++++++++++ 8 files changed, 216 insertions(+) create mode 100644 interface/resources/qml/hifi/AvatarPackager.qml create mode 100644 interface/src/avatar/AvatarPackager.cpp create mode 100644 interface/src/avatar/AvatarPackager.h create mode 100644 interface/src/avatar/AvatarProject.cpp create mode 100644 interface/src/avatar/AvatarProject.h diff --git a/interface/resources/qml/hifi/AvatarPackager.qml b/interface/resources/qml/hifi/AvatarPackager.qml new file mode 100644 index 0000000000..787c8d6b69 --- /dev/null +++ b/interface/resources/qml/hifi/AvatarPackager.qml @@ -0,0 +1,54 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 +import QtQml.Models 2.1 +import QtGraphicalEffects 1.0 +import "../controlsUit" 1.0 as HifiControls +import "../stylesUit" 1.0 +import "../windows" as Windows +import "../dialogs" + +Windows.ScrollingWindow { + id: root + objectName: "AvatarPackager" + width: 480 + height: 706 + title: "Avatar Packager" + resizable: true + opacity: parent.opacity + destroyOnHidden: true + implicitWidth: 384; implicitHeight: 640 + minSize: Qt.vector2d(200, 300) + Rectangle { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + RalewaySemiBold { + id: displayNameLabel + size: 24; + anchors.left: parent.left + anchors.top: parent.top + anchors.topMargin: 25 + text: 'Avatar Projects' + } + + HifiControls.Button { + anchors.left: parent.left + anchors.right: parent.right + anchors.top: displayNameLabel.bottom + text: qsTr("Open Avatar Project") + // color: hifi.buttons.blue + colorScheme: root.colorScheme + height: 30 + onClicked: function() { + let avatarProject = AvatarPackagerCore.openAvatarProject(); + if (avatarProject) { + console.log("LOAD COMPLETE"); + } else { + console.log("LOAD FAILED"); + } + } + } + } +} diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0b53e24a8e..7c4975e7a9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -158,6 +158,7 @@ #include "audio/AudioScope.h" #include "avatar/AvatarManager.h" #include "avatar/MyHead.h" +#include "avatar/AvatarPackager.h" #include "CrashRecoveryHandler.h" #include "CrashHandler.h" #include "devices/DdeFaceTracker.h" @@ -912,6 +913,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); return previousSessionCrashed; } @@ -2639,6 +2641,7 @@ void Application::cleanupBeforeQuit() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); qCDebug(interfaceapp) << "Application::cleanupBeforeQuit() complete"; } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index e9a44b1e87..4056458dcc 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -35,6 +35,7 @@ #include "assets/ATPAssetMigrator.h" #include "audio/AudioScope.h" #include "avatar/AvatarManager.h" +#include "avatar/AvatarPackager.h" #include "AvatarBookmarks.h" #include "devices/DdeFaceTracker.h" #include "MainWindow.h" @@ -145,6 +146,12 @@ Menu::Menu() { addActionToQMenuAndActionHash(editMenu, MenuOption::PackageModel, 0, qApp, SLOT(packageModel())); + // Edit > Avatar Packager + action = addActionToQMenuAndActionHash(editMenu, MenuOption::AvatarPackager); + connect(action, &QAction::triggered, [] { + DependencyManager::get()->open(); + }); + // Edit > Reload All Content addActionToQMenuAndActionHash(editMenu, MenuOption::ReloadContent, 0, qApp, SLOT(reloadResourceCaches())); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 7168b7294e..3611faaf8f 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -46,6 +46,7 @@ namespace MenuOption { const QString AutoMuteAudio = "Auto Mute Microphone"; const QString AvatarReceiveStats = "Show Receive Stats"; const QString AvatarBookmarks = "Avatar Bookmarks"; + const QString AvatarPackager = "Avatar Packager"; const QString Back = "Back"; const QString BinaryEyelidControl = "Binary Eyelid Control"; const QString BookmarkAvatar = "Bookmark Avatar"; diff --git a/interface/src/avatar/AvatarPackager.cpp b/interface/src/avatar/AvatarPackager.cpp new file mode 100644 index 0000000000..ef127d4459 --- /dev/null +++ b/interface/src/avatar/AvatarPackager.cpp @@ -0,0 +1,44 @@ +// +// AvatarPackager.cpp +// +// +// Created by Thijs Wenker on 12/6/2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AvatarPackager.h" + +#include +#include +#include + +#include +#include "ModelSelector.h" + +bool AvatarPackager::open() { + static const QUrl url{ "hifi/AvatarPackager.qml" }; + + const auto packageModelDialogCreated = [=](QQmlContext* context, QObject* newObject) { + context->setContextProperty("AvatarPackagerCore", this); + }; + DependencyManager::get()->show(url, "AvatarPackager", packageModelDialogCreated); + return true; +} + +QObject* AvatarPackager::openAvatarProject() { + // TODO: use QML file browser here, could handle this on QML side instead + static Setting::Handle lastModelBrowseLocation("LastModelBrowseLocation", + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); + const QString filename = QFileDialog::getOpenFileName(nullptr, "Select your model file ...", + lastModelBrowseLocation.get(), + "Model files (*.fst *.fbx)"); + QFileInfo fileInfo(filename); + + if (fileInfo.isFile() && fileInfo.completeSuffix().contains(QRegExp("fst|fbx|FST|FBX"))) { + return AvatarProject::openAvatarProject(fileInfo.absoluteFilePath()); + } + return nullptr; +} diff --git a/interface/src/avatar/AvatarPackager.h b/interface/src/avatar/AvatarPackager.h new file mode 100644 index 0000000000..8f29f98c0b --- /dev/null +++ b/interface/src/avatar/AvatarPackager.h @@ -0,0 +1,35 @@ +// +// AvatarPackager.h +// +// +// Created by Thijs Wenker on 12/6/2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_AvatarPackager_h +#define hifi_AvatarPackager_h + +#include +#include + +#include "avatar/AvatarProject.h" + +class AvatarPackager : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY + +public: + bool open(); + + Q_INVOKABLE void openAvatarProjectWithoutReturnType() { + openAvatarProject(); + } + + Q_INVOKABLE QObject* openAvatarProject(); +}; + +#endif // hifi_AvatarPackager_h diff --git a/interface/src/avatar/AvatarProject.cpp b/interface/src/avatar/AvatarProject.cpp new file mode 100644 index 0000000000..876bd1725b --- /dev/null +++ b/interface/src/avatar/AvatarProject.cpp @@ -0,0 +1,27 @@ +// +// AvatarProject.h +// +// +// Created by Thijs Wenker on 12/7/2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AvatarProject.h" + +AvatarProject* AvatarProject::openAvatarProject(QString path) { + const auto pathToLower = path.toLower(); + if (pathToLower.endsWith(".fst")) { + // TODO: do we open FSTs from any path? + return new AvatarProject(path); + } + + if (pathToLower.endsWith(".fbx")) { + // TODO: Create FST here: + + } + + return nullptr; +} diff --git a/interface/src/avatar/AvatarProject.h b/interface/src/avatar/AvatarProject.h new file mode 100644 index 0000000000..cc347c3d4b --- /dev/null +++ b/interface/src/avatar/AvatarProject.h @@ -0,0 +1,45 @@ +// +// AvatarProject.h +// +// +// Created by Thijs Wenker on 12/7/2018 +// Copyright 2018 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_AvatarProject_h +#define hifi_AvatarProject_h + +#include + +class AvatarProject : public QObject { +public: + Q_INVOKABLE bool write() { + // Write FST here + return false; + } + + Q_INVOKABLE QObject* upload() { + // TODO: create new AvatarProjectUploader here, launch it and return it for status tracking in QML + return nullptr; + } + + /** + * returns the AvatarProject or a nullptr on failure. + */ + static AvatarProject* openAvatarProject(QString path); + +private: + AvatarProject(QString fstPath) { + + } + + ~AvatarProject() { + // TODO: cleanup FST / AvatarProjectUploader etc. + } +}; + +#endif // hifi_AvatarProject_h