Can drag blocks zip folder into hifi and upload the .obj

This commit is contained in:
Elisa Lupin-Jimenez 2017-07-26 15:21:39 -07:00
parent 4570814145
commit ca6a323d54
6 changed files with 96 additions and 38 deletions

View file

@ -230,6 +230,9 @@ static const QString OBJ_EXTENSION = ".obj";
static const QString AVA_JSON_EXTENSION = ".ava.json";
static const QString WEB_VIEW_TAG = "noDownload=true";
// temporary zip handling for Emily
static const QString ZIP_EXTENSION = ".zip";
static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND;
@ -260,7 +263,10 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi
{ AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl },
{ JSON_EXTENSION, &Application::importJSONFromURL },
{ JS_EXTENSION, &Application::askToLoadScript },
{ FST_EXTENSION, &Application::askToSetAvatarUrl }
{ FST_EXTENSION, &Application::askToSetAvatarUrl },
// temporary zip handling for Emily
{ ZIP_EXTENSION, &Application::importFromZIP }
};
class DeadlockWatchdogThread : public QThread {
@ -2779,6 +2785,15 @@ void Application::onPresent(quint32 frameCount) {
}
}
bool Application::importFromZIP(const QString& filePath) {
qDebug() << "A zip file has been dropped in: " << filePath;
QUrl empty = "";
qApp->getFileDownloadInterface()->runUnzip(filePath, empty, false, true);
return true;
}
bool _renderRequested { false };
bool Application::event(QEvent* event) {
if (!Menu::getInstance()) {
return false;
@ -6218,7 +6233,7 @@ void Application::addAssetToWorldFromURLRequestFinished() {
if (tempFile.open(QIODevice::WriteOnly)) {
tempFile.write(request->getData());
addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key.
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true);
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false);
} else {
QString errorInfo = "Couldn't open temporary file for download";
qWarning(interfaceapp) << errorInfo;

View file

@ -482,6 +482,9 @@ private:
bool importJSONFromURL(const QString& urlString);
bool importSVOFromURL(const QString& urlString);
// temporary zip handling for Emily
bool importFromZIP(const QString& filePath);
bool nearbyEntitiesAreReadyForPhysics();
int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode);
void trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket);

View file

@ -32,12 +32,19 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent
// nothing for now
}
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks) {
qCDebug(scriptengine) << "Url that was downloaded: " + url.toString();
qCDebug(scriptengine) << "Path where download is saved: " + path;
QString fileName = "/" + path.section("/", -1);
QString tempDir = path;
if (!isBlocks) {
tempDir.remove(fileName);
} else {
QTemporaryDir blocks;
tempDir = blocks.path();
path.remove("file:///");
}
qCDebug(scriptengine) << "Temporary directory at: " + tempDir;
if (!isTempDir(tempDir)) {
qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files";
@ -45,6 +52,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
}
QString file = unzipFile(path, tempDir);
qCDebug(scriptengine) << "Unzipped file: " << file;
QString filename = QUrl::fromLocalFile(file).toString();
if (file != "") {
qCDebug(scriptengine) << "File to upload: " + filename;
@ -54,6 +62,26 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
emit unzipResult(path, filename, autoAdd);
}
QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
QDir dir(path);
QString dirName = dir.path();
qCDebug(scriptengine) << "Directory to unzip: " << dirName;
QString target = tempDir + "/model_repo";
QStringList list = JlCompress::extractDir(dirName, target);
qCDebug(scriptengine) << list;
if (!list.isEmpty()) {
return list.front();
}
else {
qCDebug(scriptengine) << "Extraction failed";
return "";
}
}
// fix to check that we are only referring to a temporary directory
bool FileScriptingInterface::isTempDir(QString tempDir) {
QString folderName = "/" + tempDir.section("/", -1);
@ -92,24 +120,6 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) {
request->send();
}
QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
QDir dir(path);
QString dirName = dir.path();
QString target = tempDir + "/model_repo";
QStringList list = JlCompress::extractDir(dirName, target);
qCDebug(scriptengine) << list;
if (!list.isEmpty()) {
return list.front();
} else {
qCDebug(scriptengine) << "Extraction failed";
return "";
}
}
// this function is not in use
void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
/*if (!file.isDir()) {

View file

@ -24,7 +24,7 @@ public:
public slots:
QString convertUrlToPath(QUrl url);
void runUnzip(QString path, QUrl url, bool autoAdd);
void runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks);
QString getTempDir();
signals:

View file

@ -33,8 +33,8 @@
$("head").append(
'<style>' +
'#marketplace-navigation { font-family: Arial, Helvetica, sans-serif; width: 100%; height: 50px; background: #00b4ef; position: fixed; bottom: 0; z-index: 1000; }' +
'#marketplace-navigation .glyph { margin-left: 20px; margin-right: 3px; font-family: sans-serif; color: #fff; font-size: 24px; line-height: 50px; }' +
'#marketplace-navigation .text { color: #fff; font-size: 18px; line-height: 50px; vertical-align: top; position: relative; top: 1px; }' +
'#marketplace-navigation .glyph { margin-left: 10px; margin-right: 3px; font-family: sans-serif; color: #fff; font-size: 24px; line-height: 50px; }' +
'#marketplace-navigation .text { color: #fff; font-size: 16px; line-height: 50px; vertical-align: top; position: relative; top: 1px; }' +
'#marketplace-navigation input#back-button { position: absolute; left: 20px; margin-top: 12px; padding-left: 0; padding-right: 5px; }' +
'#marketplace-navigation input#all-markets { position: absolute; right: 20px; margin-top: 12px; padding-left: 15px; padding-right: 15px; }' +
'#marketplace-navigation .right { position: absolute; right: 20px; }' +
@ -79,6 +79,9 @@
letUsKnow.replaceWith(letUsKnow.html());
// Add button links.
$('#exploreBlocksMarketplace').on('click', function () {
window.location = "https://vr.google.com/objects";
});
$('#exploreClaraMarketplace').on('click', function () {
window.location = "https://clara.io/library?gameCheck=true&public=true";
});
@ -91,6 +94,16 @@
// Nothing to do.
}
function injectBlocksCode() {
// Make space for marketplaces footer in Blocks pages.
$("head").append(
'<style>' +
'#app { margin-bottom: 135px; }' +
'.footer { bottom: 50px; }' +
'</style>'
);
}
function updateClaraCode() {
// Have to repeatedly update Clara page because its content can change dynamically without location.href changing.
@ -322,10 +335,12 @@
var DIRECTORY = 0;
var HIFI = 1;
var CLARA = 2;
var BLOCKS = 2;
var CLARA = 3;
var pageType = DIRECTORY;
if (location.href.indexOf("highfidelity.com/") !== -1) { pageType = HIFI; }
if (location.href.indexOf("google.com/") !== -1) { pageType = BLOCKS; }
if (location.href.indexOf("clara.io/") !== -1) { pageType = CLARA; }
injectCommonCode(pageType === DIRECTORY);
@ -336,6 +351,9 @@
case HIFI:
injectHiFiCode();
break;
case BLOCKS:
injectBlocksCode();
break;
case CLARA:
injectClaraCode();
break;

View file

@ -30,6 +30,19 @@
</div>
<hr class="tile-divider">
</div>
</div>
<div class="marketplace-tile">
<div class="marketplace-tile-first-column">
<img class="marketplace-tile-image" src="img/blocks-tile.png">
</div>
<div class="marketplace-tile-second-column">
<p class="marketplace-tile-description">Blocks, released by Google, allows anyone to create 3D models using just a few simple tools. Browse through other users' creations for low-poly assets to add to your world.</p>
<div class="exploreButton-holder">
<input class="blue exploreButton" type="button" value="Explore" id="exploreBlocksMarketplace" />
</div>
<hr class="tile-divider">
</div>
</div>
<div class="marketplace-tile">
<div class="marketplace-tile-first-column">
<img class="marketplace-tile-image" src="img/clara-tile.png">
@ -46,7 +59,6 @@
</div>
</div>
</div>
</div>
<!-- Code similar to the following is injected; the following is included here to help with CSS styling.
<div id="marketplace-navigation">
<span class="glyph">&#x1f6c8;</span> <span class="text">Select a marketplace to explore.</span>